Class: Prependers::Loader
- Inherits:
-
Object
- Object
- Prependers::Loader
- Defined in:
- lib/prependers/loader.rb
Constant Summary collapse
- UNDEFINED_PREPENDER_ERROR =
"Expected `%{path}` to define `%{prepender}`, but it is not defined.\n\n" \ "This is most likely because the file has not been required.\n\n" \ "Require the file yourself before calling `Prependers.load_paths`."
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.
12 13 14 15 |
# File 'lib/prependers/loader.rb', line 12 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.
10 11 12 |
# File 'lib/prependers/loader.rb', line 10 def base_path @base_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/prependers/loader.rb', line 10 def @options end |
Instance Method Details
#load ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prependers/loader.rb', line 17 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_name = expected_module_for(relative_path) unless Object.const_defined?(prepender_name) raise NoPrependerError, UNDEFINED_PREPENDER_ERROR % { path: absolute_path, prepender: prepender_name, } end prepender = Object.const_get(prepender_name) if prepender.ancestors.none? { |ancestor| ancestor.is_a?(Prependers::Prepender) } prepender.include(Prepender.new()) end end end |