Sha256: ffbf0e942bae8ef61636bf372112fd9b6b5c016b26d44c50eb7e17aa4e215732

Contents?: true

Size: 924 Bytes

Versions: 7

Compression:

Stored size: 924 Bytes

Contents

require 'processors/lib/find_call'

#This processor specifically looks for calls like
# User.active.human.find(:all, :conditions => ...)
class FindModelCall < FindCall

  #Passes +targets+ to FindCall
  def initialize targets
    super(targets, /^(find.*|first|last|all|count|sum|average|minumum|maximum|count_by_sql)$/, true)
  end 

  #Matches entire method chain as a target. This differs from
  #FindCall#get_target, which only matches the first expression in the chain.
  def get_target exp
    if sexp? exp
      case exp.node_type
      when :ivar, :lvar, :const
        exp[1]
      when :true, :false
        exp[0]
      when :lit
        exp[1]
      when :colon2
        class_name exp
      when :call
        t = get_target(exp[1])
        if t and match(@find_targets, t)
          t
        else
          process exp
        end
      else
        process exp
      end
    else
      exp
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
brakeman-min-0.5.2 lib/processors/lib/find_model_call.rb
brakeman-min-0.5.1 lib/processors/lib/find_model_call.rb
brakeman-min-0.5.0 lib/processors/lib/find_model_call.rb
brakeman-min-0.4.1 lib/processors/lib/find_model_call.rb
brakeman-min-0.4.0 lib/processors/lib/find_model_call.rb
brakeman-min-0.3.2 lib/processors/lib/find_model_call.rb
brakeman-min-0.3.1 lib/processors/lib/find_model_call.rb