Skip to content

Commit

Permalink
Merge pull request #710 from aianus/search_methods_by_regex
Browse files Browse the repository at this point in the history
Allow method to be specified by regex
  • Loading branch information
presidentbeef committed Sep 5, 2015
2 parents bf5a791 + 725ed0d commit f9ce050
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/brakeman/call_index.rb
Expand Up @@ -139,6 +139,8 @@ def calls_by_targets targets
def calls_by_method method
if method.is_a? Array
calls_by_methods method
elsif method.is_a? Regexp
calls_by_methods_regex method
else
@calls_by_method[method.to_sym] || []
end
Expand All @@ -155,6 +157,14 @@ def calls_by_methods methods
calls
end

def calls_by_methods_regex methods_regex
calls = []
@calls_by_method.each do |key, value|
calls.concat value if key.to_s.match methods_regex
end
calls
end

def calls_with_no_target
@calls_by_target[nil] || []
end
Expand Down
4 changes: 4 additions & 0 deletions test/tests/call_index.rb
Expand Up @@ -16,6 +16,10 @@ def assert_found num, opts
assert @call_index.find_calls(opts).length
end

def test_find_by_method_regex
assert_found 2, :method => %r{do_it(?:_now)?}
end

def test_find_by_method
assert_found 1, :method => :hello
end
Expand Down

0 comments on commit f9ce050

Please sign in to comment.