Class: Brakeman::MethodInfo
- Inherits:
-
Object
- Object
- Brakeman::MethodInfo
- Includes:
- Util
- Defined in:
- lib/brakeman/tracker/method_info.rb
Constant Summary
Constants included from Util
Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::DIR_CONST, Util::LITERALS, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::REQUEST_REQUEST_PARAMETERS, Util::SAFE_LITERAL, Util::SESSION, Util::SESSION_SEXP, Util::SIMPLE_LITERALS
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#[](attr) ⇒ Object
To support legacy code that expected a Hash.
- #first_body ⇒ Object
-
#initialize(name, src, owner, file) ⇒ MethodInfo
constructor
A new instance of MethodInfo.
- #return_value(env = nil) ⇒ Object
- #very_simple_method? ⇒ Boolean
Methods included from Util
#all_literals?, #array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #dir_glob?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #hash_values, #integer?, #kwsplat?, #literal?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #recurse_check?, #regexp?, #remove_kwsplat, #request_headers?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #simple_literal?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore
Constructor Details
#initialize(name, src, owner, file) ⇒ MethodInfo
Returns a new instance of MethodInfo.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/brakeman/tracker/method_info.rb', line 9 def initialize name, src, owner, file @name = name @src = src @owner = owner @file = file @type = case src.node_type when :defn :instance when :defs :class else raise "Expected sexp type: #{src.node_type}" end @simple_method = nil end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/brakeman/tracker/method_info.rb', line 7 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/brakeman/tracker/method_info.rb', line 7 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
7 8 9 |
# File 'lib/brakeman/tracker/method_info.rb', line 7 def owner @owner end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
7 8 9 |
# File 'lib/brakeman/tracker/method_info.rb', line 7 def src @src end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/brakeman/tracker/method_info.rb', line 7 def type @type end |
Instance Method Details
#[](attr) ⇒ Object
To support legacy code that expected a Hash
27 28 29 |
# File 'lib/brakeman/tracker/method_info.rb', line 27 def [] attr self.send(attr) end |
#first_body ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/brakeman/tracker/method_info.rb', line 61 def first_body case @type when :class src[4] when :instance src[3] end end |
#return_value(env = nil) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/brakeman/tracker/method_info.rb', line 53 def return_value env = nil if very_simple_method? return @return_value else nil end end |
#very_simple_method? ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/brakeman/tracker/method_info.rb', line 31 def very_simple_method? return @simple_method == :very unless @simple_method.nil? # Very simple methods have one (simple) expression in the body and # no arguments if src.formal_args.length == 1 # no args if src.method_length == 1 # Single expression in body value = first_body # First expression in body if simple_literal? value or (array? value and all_literals? value) or (hash? value and all_literals? value, :hash) @return_value = value @simple_method = :very end end end @simple_method ||= false end |