Class: Metasploit::Model::Configuration::Autoload
- Defined in:
- lib/metasploit/model/configuration/autoload.rb
Overview
Defines methods for adding paths to ActiveSupport::Dependencies.autoload_paths.
Instance Attribute Summary collapse
-
#relative_once_paths ⇒ Array<String>
Paths relative to #root that are to be added to
ActiveSupport::Dependencies.autoload_pathsandActiveSupport::Dependencies.autoload_once_paths. -
#relative_paths ⇒ Array<String>
Paths relative to #root that are to be added to
ActiveSupport::Dependencies.autoload_paths, but notActiveSupport::Dependencies.autoload_once_paths.
Attributes inherited from Child
Instance Method Summary collapse
-
#all_paths ⇒ Array<String>
Combines #once_paths and #paths as both need to be added to
ActiveSupport::Dependencies.autoload_paths. -
#eager_load! ⇒ void
Eager loads all rb files under #all_paths.
-
#once_paths ⇒ Array<String>
#relative_once_paths converted to absolute paths.
-
#paths ⇒ Array<String>
#relative_paths converted to absolute paths.
-
#setup ⇒ void
Adds #all_paths to
ActiveSupport::Dependencies.autoload_pathsif they are not already there and adds #once_paths toActiveSupport::Dependencies.autoload_once_pathsif they are not already there.
Instance Attribute Details
#relative_once_paths ⇒ Array<String>
Paths relative to Metasploit::Model::Configuration#root that are to be added to
ActiveSupport::Dependencies.autoload_paths and ActiveSupport::Dependencies.autoload_once_paths.
|
|
# File 'lib/metasploit/model/configuration/autoload.rb', line 9
|
#relative_paths ⇒ Array<String>
Paths relative to Metasploit::Model::Configuration#root that are to be added to
ActiveSupport::Dependencies.autoload_paths, but not ActiveSupport::Dependencies.autoload_once_paths
|
|
# File 'lib/metasploit/model/configuration/autoload.rb', line 15
|
Instance Method Details
#all_paths ⇒ Array<String>
Combines #once_paths and #paths as both need to be added to
ActiveSupport::Dependencies.autoload_paths.
29 30 31 |
# File 'lib/metasploit/model/configuration/autoload.rb', line 29 def all_paths @all_paths ||= (once_paths + paths).uniq end |
#eager_load! ⇒ void
This method returns an undefined value.
Eager loads all rb files under #all_paths. Paths in #all_paths are sorted before loading, so that app will
load before lib. Files are required using ActiveSupport::Dependencies::Loadable#require_dependency so they
interact with ActiveSupport::Dependencies loading correctly.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/metasploit/model/configuration/autoload.rb', line 38 def eager_load! # sort to favor app over lib since it is assumed that app/models will define classes and lib will define modules # included in those classes that are defined under the class namespaces, so the class needs to be required first all_paths.sort.each do |load_path| matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/ Dir.glob("#{load_path}/**/*.rb").sort.each do |file| require_dependency file.sub(matcher, '\1') end end end |
#once_paths ⇒ Array<String>
#relative_once_paths converted to absolute paths.
53 54 55 56 57 |
# File 'lib/metasploit/model/configuration/autoload.rb', line 53 def once_paths @once_paths ||= relative_once_paths.collect { |relative_path| configuration.root.join(relative_path).to_path } end |
#paths ⇒ Array<String>
#relative_paths converted to absolute paths.
62 63 64 65 66 |
# File 'lib/metasploit/model/configuration/autoload.rb', line 62 def paths @paths ||= relative_paths.collect { |relative_path| configuration.root.join(relative_path).to_path } end |
#setup ⇒ void
This method returns an undefined value.
Adds #all_paths to ActiveSupport::Dependencies.autoload_paths if they are not already there and adds
#once_paths to ActiveSupport::Dependencies.autoload_once_paths if they are not already there.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/metasploit/model/configuration/autoload.rb', line 96 def setup all_paths.each do |autoload_path| unless ActiveSupport::Dependencies.autoload_paths.include? autoload_path ActiveSupport::Dependencies.autoload_paths << autoload_path end end once_paths.each do |autoload_once_path| unless ActiveSupport::Dependencies.autoload_once_paths.include? autoload_once_path ActiveSupport::Dependencies.autoload_once_paths << autoload_once_path end end end |