Module: Brakeman::ProcessorHelper
- Included in:
- AliasProcessor, BaseCheck, BaseProcessor, BasicProcessor
- Defined in:
- lib/brakeman/processors/lib/processor_helper.rb
Overview
Contains a couple shared methods for Processors.
Instance Method Summary collapse
- #current_file_name ⇒ Object
- #process_all(exp) ⇒ Object
- #process_all!(exp) ⇒ Object
-
#process_call_args(exp) ⇒ Object
Process the arguments of a method call.
-
#process_call_defn?(exp) ⇒ Boolean
e.g.
- #process_class(exp) ⇒ Object
-
#process_module(exp) ⇒ Object
Sets the current module.
Instance Method Details
#current_file_name ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/brakeman/processors/lib/processor_helper.rb', line 76 def current_file_name case when @file_name @file_name when @current_class.is_a?(Brakeman::Collection) @current_class.file when @current_module.is_a?(Brakeman::Collection) @current_module.file else nil end end |
#process_all(exp) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/brakeman/processors/lib/processor_helper.rb', line 3 def process_all exp exp.each_sexp do |e| process e end exp end |
#process_all!(exp) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/brakeman/processors/lib/processor_helper.rb', line 10 def process_all! exp exp.map! do |e| if sexp? e process e else e end end exp end |
#process_call_args(exp) ⇒ Object
Process the arguments of a method call. Does not store results.
This method is used because Sexp#args and Sexp#arglist create new objects.
25 26 27 28 29 30 31 |
# File 'lib/brakeman/processors/lib/processor_helper.rb', line 25 def process_call_args exp exp.each_arg do |a| process a if sexp? a end exp end |
#process_call_defn?(exp) ⇒ Boolean
e.g. private defn
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/brakeman/processors/lib/processor_helper.rb', line 64 def process_call_defn? exp if call? exp and exp.target.nil? and node_type? exp.first_arg, :defn, :defs and [:private, :public, :protected].include? exp.method prev_visibility = @visibility @visibility = exp.method process exp.first_arg @visibility = prev_visibility exp else false end end |
#process_class(exp) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/brakeman/processors/lib/processor_helper.rb', line 33 def process_class exp current_class = @current_class @current_class = class_name exp[1] process_all exp.body @current_class = current_class exp end |
#process_module(exp) ⇒ Object
Sets the current module.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/brakeman/processors/lib/processor_helper.rb', line 42 def process_module exp module_name = class_name(exp.class_name).to_s prev_module = @current_module if prev_module @current_module = "#{prev_module}::#{module_name}" else @current_module = module_name end if block_given? yield else process_all exp.body end @current_module = prev_module exp end |