From 5fca2fc5d5ec47fc12ac60c924e6c0d7cd2a3678 Mon Sep 17 00:00:00 2001 From: Justin Collins Date: Sat, 14 Feb 2015 08:19:18 -0800 Subject: [PATCH] Actually add RenderPath --- lib/brakeman/processors/lib/render_path.rb | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/brakeman/processors/lib/render_path.rb diff --git a/lib/brakeman/processors/lib/render_path.rb b/lib/brakeman/processors/lib/render_path.rb new file mode 100644 index 00000000..9fcf395f --- /dev/null +++ b/lib/brakeman/processors/lib/render_path.rb @@ -0,0 +1,93 @@ +module Brakeman + class RenderPath + attr_reader :path + + def initialize + @path = [] + end + + def add_controller_render controller_name, method_name + @path << { :type => :controller, + :class => controller_name.to_sym, + :method => method_name.to_sym } + + self + end + + def add_template_render template_name + @path << { :type => :template, + :name => template_name.to_sym } + + self + end + + def include_template? name + name = name.to_sym + + puts "Does #{@path.inspect} include #{name.inspect}?" if name.to_s.include? "circular" + @path.any? do |loc| + loc[:type] == :template and loc[:name] == name + end + end + + def include_controller? klass + klass = klass.to_sym + + @path.any? do |loc| + loc[:type] == :controller and loc[:class] == klass + end + end + + 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 + + def each &block + @path.each &block + end + + def join *args + self.to_a.join *args + end + + def length + @path.length + end + + def to_a + @path.map do |loc| + case loc[:type] + when :template + "Template:#{loc[:name]}" + when :controller + "#{loc[:class]}##{loc[:method]}" + end + end + end + + def last + self.to_a.last + end + + def to_s + self.to_a.to_s + end + + def to_sym + self.to_s.to_sym + end + + def to_json *args + self.to_a.to_json *args + end + + def initialize_copy original + @path = original.path.dup + self + end + end +end -- GitLab