Class: Prependers::Loader
- Inherits:
-
Object
- Object
- Prependers::Loader
- Defined in:
- lib/prependers/loader.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(base_path, options = {}) ⇒ Loader
constructor
A new instance of Loader.
- #load ⇒ Object
Constructor Details
#initialize(base_path, options = {}) ⇒ Loader
Returns a new instance of Loader.
7 8 9 10 |
# File 'lib/prependers/loader.rb', line 7 def initialize(base_path, = {}) @base_path = Pathname.new(File.(base_path)) @options = end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/prependers/loader.rb', line 5 def base_path @base_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/prependers/loader.rb', line 5 def @options end |
Instance Method Details
#load ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/prependers/loader.rb', line 12 def load Dir.glob("#{base_path}/**/*.rb").sort.each do |path| absolute_path = Pathname.new(File.(path)) relative_path = absolute_path.relative_path_from(base_path) prepender_module_name = expected_module_for(relative_path) unless Object.const_defined?(prepender_module_name) error = <<~ERROR Expected #{absolute_path} to define #{prepender_module_name}, but module is not defined. Note that Prependers does not require files automatically - you will have to do that yourself before calling `#load_paths`. ERROR raise NoPrependerError, error end prepender_module = Object.const_get(prepender_module_name) prepender_module.include Prepender.new([:namespace]) end end |