Sha256: 195c5c6121bca140d4c2782e0cc7adcf0c741bf4c8028a0dcc394a3a42fe8393

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 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)$/)
  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

2 entries across 2 versions & 2 rubygems

Version Path
brakeman-min-0.3.0 lib/processors/lib/find_model_call.rb
brakeman-0.3.0 lib/processors/lib/find_model_call.rb