make some methods less complex and adjust rubocop-rules
This commit is contained in:
parent
c950e7a94b
commit
5ac7a14b1e
3 changed files with 42 additions and 26 deletions
19
.rubocop.yml
19
.rubocop.yml
|
|
@ -18,9 +18,6 @@ Metrics/MethodLength:
|
||||||
Metrics/ClassLength:
|
Metrics/ClassLength:
|
||||||
Max: 1500
|
Max: 1500
|
||||||
|
|
||||||
Metrics/ModuleLength:
|
|
||||||
Max: 1500
|
|
||||||
|
|
||||||
# No space makes the method definition shorter and differentiates
|
# No space makes the method definition shorter and differentiates
|
||||||
# from a regular assignment.
|
# from a regular assignment.
|
||||||
Style/SpaceAroundEqualsInParameterDefault:
|
Style/SpaceAroundEqualsInParameterDefault:
|
||||||
|
|
@ -142,3 +139,19 @@ Lint/Debugger:
|
||||||
# Reset some HoundCI changes back to Rubocop defaults
|
# Reset some HoundCI changes back to Rubocop defaults
|
||||||
Style/DotPosition:
|
Style/DotPosition:
|
||||||
EnforcedStyle: leading
|
EnforcedStyle: leading
|
||||||
|
|
||||||
|
|
||||||
|
# diaspora_federation rules
|
||||||
|
Rails/TimeZone:
|
||||||
|
Exclude:
|
||||||
|
- "spec/**/*"
|
||||||
|
|
||||||
|
Metrics/CyclomaticComplexity:
|
||||||
|
Max: 10
|
||||||
|
Metrics/PerceivedComplexity:
|
||||||
|
Max: 10
|
||||||
|
Metrics/AbcSize:
|
||||||
|
Max: 20
|
||||||
|
|
||||||
|
Metrics/ModuleLength:
|
||||||
|
Max: 1500
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,12 @@ module DiasporaFederation
|
||||||
|
|
||||||
return logger.warn "table for #{entity} doesn't exist, skip validation" unless entity.table_exists?
|
return logger.warn "table for #{entity} doesn't exist, skip validation" unless entity.table_exists?
|
||||||
|
|
||||||
methods.each {|method|
|
methods.each {|method| entity_respond_to?(entity, method) }
|
||||||
valid = entity.respond_to?(method) ||
|
end
|
||||||
entity.column_names.include?(method.to_s) ||
|
|
||||||
entity.method_defined?(method)
|
def entity_respond_to?(entity, method)
|
||||||
|
valid = entity.respond_to?(method) || entity.column_names.include?(method.to_s) || entity.method_defined?(method)
|
||||||
raise ConfigurationError, "the configured class #{entity} for #{name} doesn't respond to #{method}" unless valid
|
raise ConfigurationError, "the configured class #{entity} for #{name} doesn't respond to #{method}" unless valid
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,24 +107,24 @@ module DiasporaFederation
|
||||||
# Create a WebFinger instance from the given XML string.
|
# Create a WebFinger instance from the given XML string.
|
||||||
# @param [String] webfinger_xml WebFinger XML string
|
# @param [String] webfinger_xml WebFinger XML string
|
||||||
# @return [WebFinger] WebFinger instance
|
# @return [WebFinger] WebFinger instance
|
||||||
|
# @raise [InvalidData] if the given XML string is invalid or incomplete
|
||||||
def self.from_xml(webfinger_xml)
|
def self.from_xml(webfinger_xml)
|
||||||
data = XrdDocument.xml_data(webfinger_xml)
|
data = parse_xml_and_validate(webfinger_xml)
|
||||||
raise InvalidData unless xml_data_valid?(data)
|
|
||||||
|
|
||||||
hcard, seed, guid, profile, updates, pubkey = parse_links(data)
|
hcard_url, seed_url, guid, profile_url, updates_url, pubkey = parse_links(data)
|
||||||
|
|
||||||
wf = allocate
|
wf = allocate
|
||||||
wf.instance_eval {
|
wf.instance_eval {
|
||||||
@acct_uri = data[:subject]
|
@acct_uri = data[:subject]
|
||||||
@alias_url = data[:aliases].first
|
@alias_url = data[:aliases].first
|
||||||
@hcard_url = hcard[:href]
|
@hcard_url = hcard_url
|
||||||
@seed_url = seed[:href]
|
@seed_url = seed_url
|
||||||
@profile_url = profile[:href]
|
@profile_url = profile_url
|
||||||
@updates_url = updates[:href]
|
@updates_url = updates_url
|
||||||
|
|
||||||
# TODO: change me! ##########
|
# TODO: change me! ##########
|
||||||
@guid = guid[:href]
|
@guid = guid
|
||||||
@pubkey = pubkey[:href]
|
@pubkey = pubkey
|
||||||
##############################
|
##############################
|
||||||
}
|
}
|
||||||
wf
|
wf
|
||||||
|
|
@ -144,14 +144,17 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
private_class_method :account_data_complete?
|
private_class_method :account_data_complete?
|
||||||
|
|
||||||
# Does some rudimentary checking on the data Hash produced from parsing the
|
# Parses the XML string to a Hash and does some rudimentary checking on
|
||||||
# XML string
|
# the data Hash.
|
||||||
# @param [Hash] data XML data
|
# @param [String] webfinger_xml WebFinger XML string
|
||||||
# @return [Boolean] validation result
|
# @return [Hash] data XML data
|
||||||
def self.xml_data_valid?(data)
|
# @raise [InvalidData] if the given XML string is invalid or incomplete
|
||||||
data.key?(:subject) && data.key?(:aliases) && data.key?(:links)
|
def self.parse_xml_and_validate(webfinger_xml)
|
||||||
|
data = XrdDocument.xml_data(webfinger_xml)
|
||||||
|
raise InvalidData unless data.key?(:subject) && data.key?(:aliases) && data.key?(:links)
|
||||||
|
data
|
||||||
end
|
end
|
||||||
private_class_method :xml_data_valid?
|
private_class_method :parse_xml_and_validate
|
||||||
|
|
||||||
def add_links_to(doc)
|
def add_links_to(doc)
|
||||||
doc.links << {rel: REL_HCARD,
|
doc.links << {rel: REL_HCARD,
|
||||||
|
|
@ -190,7 +193,7 @@ module DiasporaFederation
|
||||||
updates = parse_link(links, REL_UPDATES)
|
updates = parse_link(links, REL_UPDATES)
|
||||||
pubkey = parse_link(links, REL_PUBKEY)
|
pubkey = parse_link(links, REL_PUBKEY)
|
||||||
raise InvalidData unless [hcard, seed, guid, profile, updates, pubkey].all?
|
raise InvalidData unless [hcard, seed, guid, profile, updates, pubkey].all?
|
||||||
[hcard, seed, guid, profile, updates, pubkey]
|
[hcard[:href], seed[:href], guid[:href], profile[:href], updates[:href], pubkey[:href]]
|
||||||
end
|
end
|
||||||
private_class_method :parse_links
|
private_class_method :parse_links
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue