Class: Brakeman::AppTree
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
Instance Attribute Details
Class Method Details
.from_options(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/brakeman/app_tree.rb', line 7 def self.() root = [:app_path] # Convert files into Regexp for matching = {} if [:skip_files] [:skip_files] = Regexp.new("(?:" << [:skip_files].map { |f| Regexp.escape f }.join("|") << ")$") end if [:only_files] [:only_files] = Regexp.new("(?:" << [:only_files].map { |f| Regexp.escape f }.join("|") << ")") end new(root, ) end |
Instance Method Details
#controller_paths ⇒ Object
56 57 58 |
# File 'lib/brakeman/app_tree.rb', line 56 def controller_paths @controller_paths ||= find_paths("app/controllers") end |
#exists?(path) ⇒ Boolean
43 44 45 |
# File 'lib/brakeman/app_tree.rb', line 43 def exists?(path) File.exists?(File.join(@root, path)) end |
#expand_path(path) ⇒ Object
27 28 29 |
# File 'lib/brakeman/app_tree.rb', line 27 def (path) File.(path, @root) end |
#initializer_paths ⇒ Object
52 53 54 |
# File 'lib/brakeman/app_tree.rb', line 52 def initializer_paths @initializer_paths ||= find_paths("config/initializers") end |
#layout_exists?(name) ⇒ Boolean
68 69 70 71 |
# File 'lib/brakeman/app_tree.rb', line 68 def layout_exists?(name) pattern = "#{@root}/{engines/*/,}app/views/layouts/#{name}.html.{erb,haml,slim}" !Dir.glob(pattern).empty? end |
#lib_paths ⇒ Object
73 74 75 |
# File 'lib/brakeman/app_tree.rb', line 73 def lib_paths @lib_files ||= find_paths("lib").reject { |path| path.include? "/generators/" } end |
#model_paths ⇒ Object
60 61 62 |
# File 'lib/brakeman/app_tree.rb', line 60 def model_paths @model_paths ||= find_paths("app/models") end |
#path_exists?(path) ⇒ Boolean
This is a pair for #read_path. Again, would like to kill these
48 49 50 |
# File 'lib/brakeman/app_tree.rb', line 48 def path_exists?(path) File.exists?(path) end |
#read(path) ⇒ Object
31 32 33 |
# File 'lib/brakeman/app_tree.rb', line 31 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.
39 40 41 |
# File 'lib/brakeman/app_tree.rb', line 39 def read_path(path) File.read(path) end |
#template_paths ⇒ Object
64 65 66 |
# File 'lib/brakeman/app_tree.rb', line 64 def template_paths @template_paths ||= find_paths("app/views", "*.{#{VIEW_EXTENSIONS}}") end |