Class: Brakeman::AppTree
- Inherits:
-
Object
- Object
- Brakeman::AppTree
- Defined in:
- lib/brakeman/app_tree.rb
Constant Summary collapse
- VIEW_EXTENSIONS =
%w[html.erb html.haml rhtml js.erb html.slim].join(",")
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #controller_paths ⇒ Object
- #exists?(path) ⇒ Boolean
- #expand_path(path) ⇒ Object
-
#initialize(root, init_options = {}) ⇒ AppTree
constructor
A new instance of AppTree.
- #initializer_paths ⇒ Object
- #layout_exists?(name) ⇒ Boolean
- #lib_paths ⇒ Object
- #model_paths ⇒ Object
-
#path_exists?(path) ⇒ Boolean
This is a pair for #read_path.
- #read(path) ⇒ Object
-
#read_path(path) ⇒ Object
This variation requires full paths instead of paths based off the project root.
- #template_paths ⇒ Object
Constructor Details
#initialize(root, init_options = {}) ⇒ AppTree
Returns a new instance of AppTree.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/brakeman/app_tree.rb', line 55 def initialize(root, = {}) @root = root @project_root_path = Pathname.new(@root) @skip_files = [:skip_files] @only_files = [:only_files] @additional_libs_path = [:additional_libs_path] || [] @engine_paths = [:engine_paths] || [] @absolute_engine_paths = @engine_paths.select { |path| path.start_with?(File::SEPARATOR) } @relative_engine_paths = @engine_paths - @absolute_engine_paths end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/brakeman/app_tree.rb', line 7 def root @root end |
Class Method Details
.from_options(options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/brakeman/app_tree.rb', line 9 def self.() root = File. [:app_path] # Convert files into Regexp for matching = {} if [:skip_files] [:skip_files] = regex_for_paths([:skip_files]) end if [:only_files] [:only_files] = regex_for_paths([:only_files]) end [:additional_libs_path] = [:additional_libs_path] [:engine_paths] = [:engine_paths] new(root, ) end |
Instance Method Details
#controller_paths ⇒ Object
95 96 97 |
# File 'lib/brakeman/app_tree.rb', line 95 def controller_paths @controller_paths ||= prioritize_concerns(find_paths("app/**/controllers")) end |
#exists?(path) ⇒ Boolean
82 83 84 |
# File 'lib/brakeman/app_tree.rb', line 82 def exists?(path) File.exist?(File.join(@root, path)) end |
#expand_path(path) ⇒ Object
66 67 68 |
# File 'lib/brakeman/app_tree.rb', line 66 def (path) File.(path, @root) end |
#initializer_paths ⇒ Object
91 92 93 |
# File 'lib/brakeman/app_tree.rb', line 91 def initializer_paths @initializer_paths ||= prioritize_concerns(find_paths("config/initializers")) end |
#layout_exists?(name) ⇒ Boolean
108 109 110 |
# File 'lib/brakeman/app_tree.rb', line 108 def layout_exists?(name) !Dir.glob("#{root_search_pattern}app/views/layouts/#{name}.html.{erb,haml,slim}").empty? end |
#lib_paths ⇒ Object
112 113 114 115 116 117 |
# File 'lib/brakeman/app_tree.rb', line 112 def lib_paths @lib_files ||= find_paths("lib").reject { |path| path.include? "/generators/" or path.include? "lib/tasks/" or path.include? "lib/templates/" } + find_additional_lib_paths + find_helper_paths + find_job_paths end |
#model_paths ⇒ Object
99 100 101 |
# File 'lib/brakeman/app_tree.rb', line 99 def model_paths @model_paths ||= prioritize_concerns(find_paths("app/**/models")) end |
#path_exists?(path) ⇒ Boolean
This is a pair for #read_path. Again, would like to kill these
87 88 89 |
# File 'lib/brakeman/app_tree.rb', line 87 def path_exists?(path) File.exist?(path) end |
#read(path) ⇒ Object
70 71 72 |
# File 'lib/brakeman/app_tree.rb', line 70 def read(path) File.read(File.join(@root, path)) end |
#read_path(path) ⇒ Object
This variation requires full paths instead of paths based off the project root. I’d prefer to get all the code outside of AppTree using project-root based paths (e.g. app/models/user.rb) instead of full paths, but I suspect it’s an incompatible change.
78 79 80 |
# File 'lib/brakeman/app_tree.rb', line 78 def read_path(path) File.read(path) end |
#template_paths ⇒ Object
103 104 105 106 |
# File 'lib/brakeman/app_tree.rb', line 103 def template_paths @template_paths ||= find_paths("app/**/views", "*.{#{VIEW_EXTENSIONS}}") + find_paths("app/**/views", "*.{erb,haml,slim}").reject { |path| File.basename(path).count(".") > 1 } end |