Class: Datasets::LazyLoader
- Inherits:
-
Object
- Object
- Datasets::LazyLoader
- Defined in:
- lib/datasets/lazy.rb
Instance Method Summary collapse
- #constant_names ⇒ Object
- #exist?(constant_name) ⇒ Boolean
-
#initialize ⇒ LazyLoader
constructor
A new instance of LazyLoader.
- #load(constant_name) ⇒ Object
- #load_all ⇒ Object
- #register(constant_name, feature) ⇒ Object
Constructor Details
#initialize ⇒ LazyLoader
Returns a new instance of LazyLoader.
5 6 7 |
# File 'lib/datasets/lazy.rb', line 5 def initialize @constants = {} end |
Instance Method Details
#constant_names ⇒ Object
29 30 31 |
# File 'lib/datasets/lazy.rb', line 29 def constant_names @constants.keys end |
#exist?(constant_name) ⇒ Boolean
9 10 11 |
# File 'lib/datasets/lazy.rb', line 9 def exist?(constant_name) @constants.key?(constant_name) end |
#load(constant_name) ⇒ Object
13 14 15 16 17 |
# File 'lib/datasets/lazy.rb', line 13 def load(constant_name) feature = @constants[constant_name] raise LoadError, "unknown dataset: #{constant_name}" unless feature require feature end |
#load_all ⇒ Object
19 20 21 22 23 |
# File 'lib/datasets/lazy.rb', line 19 def load_all @constants.each_value do |feature| require feature end end |
#register(constant_name, feature) ⇒ Object
25 26 27 |
# File 'lib/datasets/lazy.rb', line 25 def register(constant_name, feature) @constants[constant_name] = feature end |