Class: Brakeman::Constant
- Inherits:
-
Object
- Object
- Brakeman::Constant
- Defined in:
- lib/brakeman/tracker/constants.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#name_array ⇒ Object
readonly
Returns the value of attribute name_array.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name, value, context = {}) ⇒ Constant
constructor
A new instance of Constant.
- #line ⇒ Object
- #match?(name) ⇒ Boolean
- #set_name(name, context) ⇒ Object
Constructor Details
#initialize(name, value, context = {}) ⇒ Constant
Returns a new instance of Constant.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/brakeman/tracker/constants.rb', line 7 def initialize name, value, context = {} set_name name, context @value = value @context = context if @context if @context[:class].is_a? Brakeman::Controller @context[:class] = @context[:class].name end @file = @context[:file] end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/brakeman/tracker/constants.rb', line 5 def context @context end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/brakeman/tracker/constants.rb', line 5 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/brakeman/tracker/constants.rb', line 5 def name @name end |
#name_array ⇒ Object (readonly)
Returns the value of attribute name_array.
5 6 7 |
# File 'lib/brakeman/tracker/constants.rb', line 5 def name_array @name_array end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/brakeman/tracker/constants.rb', line 5 def value @value end |
Instance Method Details
#line ⇒ Object
21 22 23 24 25 |
# File 'lib/brakeman/tracker/constants.rb', line 21 def line if @value.is_a? Sexp @value.line end end |
#match?(name) ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/brakeman/tracker/constants.rb', line 32 def match? name if name == @name return true elsif name.is_a? Sexp and name.node_type == :const and name.value == @name return true elsif name.is_a? Symbol and name.value == @name return true elsif name.class == Array name == @name_array or @name_array.reverse.zip(name.reverse).reduce(true) { |m, a| a[1] ? a[0] == a[1] && m : m } else false end end |
#set_name(name, context) ⇒ Object
27 28 29 30 |
# File 'lib/brakeman/tracker/constants.rb', line 27 def set_name name, context @name = name @name_array = Constants.constant_as_array(name) end |