Skip to content

Commit

Permalink
De-duplicate validation methods inside of the linter
Browse files Browse the repository at this point in the history
Validation hook runners were essentially the same except by whom they
were targetting.
  • Loading branch information
joshkalpin committed Dec 6, 2013
1 parent 6b3de00 commit b24e8d8
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions lib/cocoapods-core/specification/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,7 @@ def check_required_root_attributes
#
def run_root_validation_hooks
attributes = DSL.attributes.values.select(&:root_only?)
attributes.each do |attr|
validation_hook = "_validate_#{attr.name}"
next unless respond_to?(validation_hook, true)
value = spec.send(attr.name)
next unless value
send(validation_hook, value)
end
run_validation_hooks(attributes, spec)
end

# Run validations for multi-platform attributes activating .
Expand Down Expand Up @@ -174,13 +168,7 @@ def perform_all_specs_analysis
#
def run_all_specs_validation_hooks
attributes = DSL.attributes.values.reject(&:root_only?)
attributes.each do |attr|
validation_hook = "_validate_#{attr.name}"
next unless respond_to?(validation_hook, true)
value = consumer.send(attr.name)
next unless value
send(validation_hook, value)
end
run_validation_hooks(attributes, consumer)
end

# Runs the validation hook for each attribute.
Expand All @@ -191,9 +179,15 @@ def run_all_specs_validation_hooks
#
# @return [void]
#
# def run_validation_hooks(attributes)
#
# end
def run_validation_hooks(attributes, target)
attributes.each do |attr|
validation_hook = "_validate_#{attr.name}"
next unless respond_to?(validation_hook, true)
value = target.send(attr.name)
next unless value
send(validation_hook, value)
end
end

#-----------------------------------------------------------------------#

Expand Down

1 comment on commit b24e8d8

@fabiopelosin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 ^ 💯

Please sign in to comment.