Class: Brakeman::LibraryProcessor

Inherits:
BaseProcessor show all
Includes:
ModuleHelper
Defined in:
lib/brakeman/processors/library_processor.rb

Overview

Process generic library and stores it in Tracker.libs

Constant Summary

Constants inherited from BaseProcessor

BaseProcessor::IGNORE

Constants included from Util

Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods included from ModuleHelper

#handle_class, #handle_module

Methods inherited from BaseProcessor

#find_render_type, #ignore, #make_inline_render, #make_render, #make_render_in_view, #process_arglist, #process_attrasgn, #process_block, #process_cdecl, #process_default, #process_dstr, #process_evstr, #process_file, #process_hash, #process_if, #process_ignore, #process_lasgn, #process_scope

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #constant?, #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, #rails_version, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #underscore

Methods included from ProcessorHelper

#current_file_name, #process_all, #process_all!, #process_call_args, #process_call_defn?

Methods inherited from SexpProcessor

#in_context, #process, processors, #scope

Constructor Details

#initialize(tracker) ⇒ LibraryProcessor

Returns a new instance of LibraryProcessor.



10
11
12
13
14
15
16
# File 'lib/brakeman/processors/library_processor.rb', line 10

def initialize tracker
  super
  @file_name = nil
  @alias_processor = Brakeman::AliasProcessor.new tracker
  @current_module = nil
  @current_class = nil
end

Instance Method Details

#process_call(exp) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/brakeman/processors/library_processor.rb', line 47

def process_call exp
  if process_call_defn? exp
    exp
  else
    process_default exp
  end
end

#process_class(exp) ⇒ Object



23
24
25
# File 'lib/brakeman/processors/library_processor.rb', line 23

def process_class exp
  handle_class exp, @tracker.libs, Brakeman::Library
end

#process_defn(exp) ⇒ Object Also known as: process_defs



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/brakeman/processors/library_processor.rb', line 31

def process_defn exp
  exp = @alias_processor.process exp

  if @current_class
    exp.body = process_all! exp.body
    @current_class.add_method :public, exp.method_name, exp, @file_name
  elsif @current_module
    exp.body = process_all! exp.body
    @current_module.add_method :public, exp.method_name, exp, @file_name
  end

  exp
end

#process_iter(exp) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/brakeman/processors/library_processor.rb', line 55

def process_iter exp
  res = process_default exp

  if node_type? res, :iter and call? exp.block_call # sometimes this changes after processing
    if exp.block_call.method == :included
      (@current_module || @current_class).options[:included] = res.block
    end
  end

  res
end

#process_library(src, file_name = nil) ⇒ Object



18
19
20
21
# File 'lib/brakeman/processors/library_processor.rb', line 18

def process_library src, file_name = nil
  @file_name = file_name
  process src
end

#process_module(exp) ⇒ Object



27
28
29
# File 'lib/brakeman/processors/library_processor.rb', line 27

def process_module exp
  handle_module exp, Brakeman::Library
end