Class: Manufacturable::Registrar

Inherits:
Object
  • Object
show all
Defined in:
lib/manufacturable/registrar.rb

Constant Summary collapse

ALL_KEY =
:__all__
DEFAULT_KEY =
:__default__

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry, type, key) ⇒ Registrar

Returns a new instance of Registrar.



36
37
38
# File 'lib/manufacturable/registrar.rb', line 36

def initialize(registry, type, key)
  @registry, @type, @key = registry, type, key
end

Class Method Details

.get(type, key) ⇒ Object



13
14
15
# File 'lib/manufacturable/registrar.rb', line 13

def get(type, key)
  self.new(registry, type, key).get
end

.register(type, key, value) ⇒ Object



9
10
11
# File 'lib/manufacturable/registrar.rb', line 9

def register(type, key, value)
  self.new(registry, type, key).register(value)
end

.registered_keys(type) ⇒ Object



21
22
23
# File 'lib/manufacturable/registrar.rb', line 21

def registered_keys(type)
  registry[type].keys
end

.registered_typesObject



17
18
19
# File 'lib/manufacturable/registrar.rb', line 17

def registered_types
  registry.keys
end

.reset!Object



25
26
27
# File 'lib/manufacturable/registrar.rb', line 25

def reset!
  registry.clear
end

Instance Method Details

#getObject



45
46
47
# File 'lib/manufacturable/registrar.rb', line 45

def get
  merged_values.empty? ? default_values : merged_values
end

#register(value) ⇒ Object



40
41
42
43
# File 'lib/manufacturable/registrar.rb', line 40

def register(value)
  assign_set if set.nil?
  set.add(value)
end