Class: Brakeman::Constant
- Inherits:
-
Object
- Object
- Brakeman::Constant
- Defined in:
- lib/brakeman/tracker/constants.rb
Instance Attribute Summary collapse
-
#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 = nil, context = nil) ⇒ Constant
constructor
A new instance of Constant.
- #line ⇒ Object
- #match?(name) ⇒ Boolean
- #set_name(name, context) ⇒ Object
Constructor Details
#initialize(name, value = nil, context = nil) ⇒ Constant
Returns a new instance of Constant.
7 8 9 10 11 12 13 14 15 |
# File 'lib/brakeman/tracker/constants.rb', line 7 def initialize name, value = nil, context = nil set_name name, context @value = value @context = context if @context @file = @context[:file] end end |
Instance Attribute Details
#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
17 18 19 20 21 |
# File 'lib/brakeman/tracker/constants.rb', line 17 def line if @value.is_a? Sexp @value.line end end |
#match?(name) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/brakeman/tracker/constants.rb', line 28 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
23 24 25 26 |
# File 'lib/brakeman/tracker/constants.rb', line 23 def set_name name, context @name = name @name_array = Constants.constant_as_array(name) end |