Class: Datasets::LazyLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/datasets/lazy.rb

Instance Method Summary collapse

Constructor Details

#initializeLazyLoader

Returns a new instance of LazyLoader.



5
6
7
# File 'lib/datasets/lazy.rb', line 5

def initialize
  @constants = {}
end

Instance Method Details

#constant_namesObject



29
30
31
# File 'lib/datasets/lazy.rb', line 29

def constant_names
  @constants.keys
end

#exist?(constant_name) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/datasets/lazy.rb', line 9

def exist?(constant_name)
  @constants.key?(constant_name)
end

#load(constant_name) ⇒ Object

Raises:

  • (LoadError)


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_allObject



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