Class: Narabikae::OptionStore

Inherits:
Object
  • Object
show all
Defined in:
lib/narabikae/option_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptionStore

Returns a new instance of OptionStore.



5
6
7
# File 'lib/narabikae/option_store.rb', line 5

def initialize
  @store = {}
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



3
4
5
# File 'lib/narabikae/option_store.rb', line 3

def store
  @store
end

Instance Method Details

#register!(field, option) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/narabikae/option_store.rb', line 9

def register!(field, option)
  if store.key?(field)
    raise Narabikae::Error, "the field `#{field}` is already registered"
  end
  if option.scope.include?(field)
    raise Narabikae::Error, "dependency loop detected: #{option.scope}"
  end
  if option.scope.any? { |s| store.key?(s) }
    raise Narabikae::Error, "the scope `#{option.scope}` is already registered as other field"
  end

  store[field] = option

  option
end