Parent

Class/Module Index [+]

Quicksearch

Brakeman::CallIndex

Stores call sites to look up later.

Public Class Methods

new(calls) click to toggle source

Initialize index with calls from FindAllCalls

# File lib/brakeman/call_index.rb, line 7
def initialize calls
  @calls_by_method = Hash.new { |h,k| h[k] = [] }
  @calls_by_target = Hash.new { |h,k| h[k] = [] }

  index_calls calls
end

Public Instance Methods

find_calls(options) click to toggle source

Find calls matching specified option hash.

Options:

* :target - symbol, array of symbols, or regular expression to match target(s)
* :method - symbol, array of symbols, or regular expression to match method(s)
* :chained - boolean, whether or not to match against a whole method chain (false by default)
* :nested - boolean, whether or not to match against a method call that is a target itself (false by default)
# File lib/brakeman/call_index.rb, line 22
def find_calls options
  target = options[:target] || options[:targets]
  method = options[:method] || options[:methods]
  nested = options[:nested]

  if options[:chained]
    return find_chain options
  #Find by narrowest category
  elsif target and method and target.is_a? Array and method.is_a? Array
    if target.length > method.length
      calls = filter_by_target calls_by_methods(method), target
    else
      calls = calls_by_targets(target)
      calls = filter_by_method calls, method
    end

  #Find by target, then by methods, if provided
  elsif target
    calls = calls_by_target target

    if calls and method
      calls = filter_by_method calls, method
    end

  #Find calls with no explicit target
  #with either :target => nil or :target => false
  elsif options.key? :target and not target and method
    calls = calls_by_method method
    calls = filter_by_target calls, nil

  #Find calls by method
  elsif method
    calls = calls_by_method method
  else
    notify "Invalid arguments to CallCache#find_calls: #{options.inspect}"
  end

  return [] if calls.nil?

  #Remove calls that are actually targets of other calls
  #Unless those are explicitly desired
  calls = filter_nested calls unless nested

  calls
end
index_calls(calls) click to toggle source
# File lib/brakeman/call_index.rb, line 96
def index_calls calls
  calls.each do |call|
    @calls_by_method[call[:method]] << call

    unless call[:target].is_a? Sexp
      @calls_by_target[call[:target]] << call
    end
  end
end
remove_indexes_by_class(classes) click to toggle source
# File lib/brakeman/call_index.rb, line 82
def remove_indexes_by_class classes
  @calls_by_method.each do |name, calls|
    calls.delete_if do |call|
      call[:location][0] == :class and classes.include? call[:location][1]
    end
  end

  @calls_by_target.each do |name, calls|
    calls.delete_if do |call|
      call[:location][0] == :class and classes.include? call[:location][1]
    end
  end
end
remove_template_indexes(template_name = nil) click to toggle source
# File lib/brakeman/call_index.rb, line 68
def remove_template_indexes template_name = nil
  @calls_by_method.each do |name, calls|
    calls.delete_if do |call|
      from_template call, template_name
    end
  end

  @calls_by_target.each do |name, calls|
    calls.delete_if do |call|
      from_template call, template_name
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.