Skip to content

Commit

Permalink
style: dry up rule extraction code when parsing pact
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jul 12, 2018
1 parent 50d5f6d commit 325a21b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/pact/matching_rules/merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def recurse_hash hash, path
end

def recurse_array array, path
parent_match_rule = @matching_rules[path] && @matching_rules[path]['match']
parent_match_rule = find_rule(path, 'match')
log_used_rule(path, 'match', parent_match_rule) if parent_match_rule

array_like_children_path = "#{path}[*]*"
children_match_rule = @matching_rules[array_like_children_path] && @matching_rules[array_like_children_path]['match']
children_match_rule = find_rule(array_like_children_path, 'match')
log_used_rule(array_like_children_path, 'match', children_match_rule) if children_match_rule

min = @matching_rules[path] && @matching_rules[path]['min']
min = find_rule(path, 'min')
log_used_rule(path, 'min', min) if min

if min && (children_match_rule == 'type' || (children_match_rule.nil? && parent_match_rule == 'type'))
Expand Down Expand Up @@ -114,6 +114,10 @@ def log_ignored_rules
end
end

def find_rule(path, key)
@matching_rules[path] && @matching_rules[path][key]
end

def log_used_rule path, key, value
@used_rules << [path, key, value]
end
Expand Down

0 comments on commit 325a21b

Please sign in to comment.