Class: Brakeman::Constant

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/brakeman/tracker/constants.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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #dir_glob?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #kwsplat?, #literal?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #remove_kwsplat, #request_env?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore

Constructor Details

#initialize(name, value, context = {}) ⇒ Constant

Returns a new instance of Constant.


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/brakeman/tracker/constants.rb', line 10

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

#contextObject (readonly)

Returns the value of attribute context


8
9
10
# File 'lib/brakeman/tracker/constants.rb', line 8

def context
  @context
end

#fileObject (readonly)

Returns the value of attribute file


8
9
10
# File 'lib/brakeman/tracker/constants.rb', line 8

def file
  @file
end

#nameObject (readonly)

Returns the value of attribute name


8
9
10
# File 'lib/brakeman/tracker/constants.rb', line 8

def name
  @name
end

#name_arrayObject (readonly)

Returns the value of attribute name_array


8
9
10
# File 'lib/brakeman/tracker/constants.rb', line 8

def name_array
  @name_array
end

#valueObject (readonly)

Returns the value of attribute value


8
9
10
# File 'lib/brakeman/tracker/constants.rb', line 8

def value
  @value
end

Instance Method Details

#lineObject


24
25
26
27
28
# File 'lib/brakeman/tracker/constants.rb', line 24

def line
  if @value.is_a? Sexp
    @value.line
  end
end

#match?(name) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/brakeman/tracker/constants.rb', line 35

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


30
31
32
33
# File 'lib/brakeman/tracker/constants.rb', line 30

def set_name name, context
  @name = name
  @name_array = Constants.constant_as_array(name)
end