Class: Brakeman::LibraryProcessor
- Inherits:
-
BaseProcessor
- Object
- SexpProcessor
- BaseProcessor
- Brakeman::LibraryProcessor
- Defined in:
- lib/brakeman/processors/library_processor.rb
Overview
Process generic library and stores it in Tracker.libs
Constant Summary
Constants inherited from BaseProcessor
Constants included from Util
Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP
Constants inherited from SexpProcessor
Instance Attribute Summary
Attributes inherited from SexpProcessor
Instance Method Summary collapse
-
#initialize(tracker) ⇒ LibraryProcessor
constructor
A new instance of LibraryProcessor.
- #process_class(exp) ⇒ Object
- #process_defn(exp) ⇒ Object
- #process_defs(exp) ⇒ Object
- #process_library(src, file_name = nil) ⇒ Object
- #process_module(exp) ⇒ Object
Methods inherited from BaseProcessor
#find_render_type, #ignore, #make_render, #make_render_in_view, #process_arglist, #process_attrasgn, #process_block, #process_default, #process_dstr, #process_evstr, #process_hash, #process_if, #process_ignore, #process_iter, #process_lasgn, #process_scope
Methods included from Util
#array?, #block?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #github_url, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #make_call, #node_type?, #number?, #params?, #pluralize, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #underscore
Methods included from ProcessorHelper
#class_name, #process_all, #process_all!, #process_call_args
Methods inherited from SexpProcessor
#error_handler, #in_context, #process, #process_dummy, processors, #scope
Constructor Details
#initialize(tracker) ⇒ LibraryProcessor
Returns a new instance of LibraryProcessor.
7 8 9 10 11 12 13 |
# File 'lib/brakeman/processors/library_processor.rb', line 7 def initialize tracker super @file_name = nil @alias_processor = Brakeman::AliasProcessor.new tracker @current_module = nil @current_class = nil end |
Instance Method Details
#process_class(exp) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/brakeman/processors/library_processor.rb', line 20 def process_class exp name = class_name(exp.class_name) parent = class_name exp.parent_name if @current_class outer_class = @current_class name = (outer_class[:name].to_s + "::" + name.to_s).to_sym end if @current_module name = (@current_module[:name].to_s + "::" + name.to_s).to_sym end if @tracker.libs[name] @current_class = @tracker.libs[name] @current_class[:files] << @file_name unless @current_class[:files].include? @file_name @current_class[:src][@file_name] = exp else @current_class = { :name => name, :parent => parent, :includes => [], :public => {}, :private => {}, :protected => {}, :src => { @file_name => exp }, :files => [ @file_name ] } @tracker.libs[name] = @current_class end exp.body = process_all! exp.body if outer_class @current_class = outer_class else @current_class = nil end exp end |
#process_defn(exp) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/brakeman/processors/library_processor.rb', line 104 def process_defn exp exp = @alias_processor.process exp exp.node_type = :methdef if @current_class exp.body = process_all! exp.body @current_class[:public][exp.method_name] = { :src => exp, :file => @file_name } elsif @current_module exp.body = process_all! exp.body @current_module[:public][exp.method_name] = { :src => exp, :file => @file_name } end exp end |
#process_defs(exp) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/brakeman/processors/library_processor.rb', line 119 def process_defs exp exp = @alias_processor.process exp exp.node_type = :selfdef if @current_class exp.body = process_all! exp.body @current_class[:public][exp.method_name] = { :src => exp, :file => @file_name } elsif @current_module exp.body = process_all! exp.body @current_module[:public][exp.method_name] = { :src => exp, :file => @file_name } end exp end |
#process_library(src, file_name = nil) ⇒ Object
15 16 17 18 |
# File 'lib/brakeman/processors/library_processor.rb', line 15 def process_library src, file_name = nil @file_name = file_name process src end |
#process_module(exp) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/brakeman/processors/library_processor.rb', line 63 def process_module exp name = class_name(exp.module_name) if @current_module outer_module = @current_module name = (outer_module[:name].to_s + "::" + name.to_s).to_sym end if @current_class name = (@current_class[:name].to_s + "::" + name.to_s).to_sym end if @tracker.libs[name] @current_module = @tracker.libs[name] @current_module[:files] << @file_name unless @current_module[:files].include? @file_name @current_module[:src][@file_name] = exp else @current_module = { :name => name, :includes => [], :public => {}, :private => {}, :protected => {}, :src => { @file_name => exp }, :files => [ @file_name ] } @tracker.libs[name] = @current_module end exp.body = process_all! exp.body if outer_module @current_module = outer_module else @current_module = nil end exp end |