Class: Brakeman::RenderPath

Inherits:
Object
  • Object
show all
Defined in:
lib/brakeman/processors/lib/render_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRenderPath

Returns a new instance of RenderPath.



5
6
7
# File 'lib/brakeman/processors/lib/render_path.rb', line 5

def initialize
  @path = []
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/brakeman/processors/lib/render_path.rb', line 3

def path
  @path
end

Instance Method Details

#add_controller_render(controller_name, method_name, line, file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/brakeman/processors/lib/render_path.rb', line 9

def add_controller_render controller_name, method_name, line, file
  method_name ||= ""

  @path << { :type => :controller,
             :class => controller_name.to_sym,
             :method => method_name.to_sym,
             :line => line,
             :file => file
            }

  self
end

#add_template_render(template_name, line, file) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/brakeman/processors/lib/render_path.rb', line 22

def add_template_render template_name, line, file
  @path << { :type => :template,
             :name => template_name.to_sym,
             :line => line,
             :file => file
           }

  self
end

#each(&block) ⇒ Object



62
63
64
# File 'lib/brakeman/processors/lib/render_path.rb', line 62

def each &block
  @path.each &block
end

#include_any_method?(method_names) ⇒ Boolean

Returns:

  • (Boolean)


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

def include_any_method? method_names
  names = method_names.map(&:to_sym)

  @path.any? do |loc|
    loc[:type] == :controller and names.include? loc[:method]
  end
end

#include_controller?(klass) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/brakeman/processors/lib/render_path.rb', line 40

def include_controller? klass
  klass = klass.to_sym

  @path.any? do |loc|
    loc[:type] == :controller and loc[:class] == klass
  end
end

#include_template?(name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/brakeman/processors/lib/render_path.rb', line 32

def include_template? name
  name = name.to_sym

  @path.any? do |loc|
    loc[:type] == :template and loc[:name] == name
  end
end

#initialize_copy(original) ⇒ Object



101
102
103
104
# File 'lib/brakeman/processors/lib/render_path.rb', line 101

def initialize_copy original
  @path = original.path.dup
  self
end

#join(*args) ⇒ Object



66
67
68
# File 'lib/brakeman/processors/lib/render_path.rb', line 66

def join *args
  self.to_a.join *args
end

#lastObject



85
86
87
# File 'lib/brakeman/processors/lib/render_path.rb', line 85

def last
  self.to_a.last
end

#lengthObject



70
71
72
# File 'lib/brakeman/processors/lib/render_path.rb', line 70

def length
  @path.length
end

#rendered_from_controller?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/brakeman/processors/lib/render_path.rb', line 56

def rendered_from_controller?
  @path.any? do |loc|
    loc[:type] == :controller
  end
end

#to_aObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/brakeman/processors/lib/render_path.rb', line 74

def to_a
  @path.map do |loc|
    case loc[:type]
    when :template
      "Template:#{loc[:name]}"
    when :controller
      "#{loc[:class]}##{loc[:method]}"
    end
  end
end

#to_json(*args) ⇒ Object



97
98
99
# File 'lib/brakeman/processors/lib/render_path.rb', line 97

def to_json *args
  MultiJson.dump(@path)
end

#to_sObject



89
90
91
# File 'lib/brakeman/processors/lib/render_path.rb', line 89

def to_s
  self.to_a.to_s
end

#to_symObject



93
94
95
# File 'lib/brakeman/processors/lib/render_path.rb', line 93

def to_sym
  self.to_s.to_sym
end