Module: StateStore::Extension::ClassMethods

Defined in:
lib/state_store/extension.rb

Instance Method Summary collapse

Instance Method Details

#has_states(*states) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/state_store/extension.rb', line 6

def has_states *states
  states_stores_options = states && states.last.is_a?(Hash) && states.pop || {}
  raise ArgumentError.new("No states given") if states.empty? 
  raise ArgumentError.new(":in is required") unless states_stores_options[:in]

  states_stores_options[:as] ||= :states
  store = StateStore::BinaryStore.new(states)

  @states_stores ||={}
  @states_stores_options ||={}
  validate_state_store(states_stores_options)

  @states_stores[states_stores_options[:as]] = store
  @states_stores_options[states_stores_options[:as]] = states_stores_options
  create_methods_for_state_store(states_stores_options[:as])
end

#states_storesObject



23
24
25
# File 'lib/state_store/extension.rb', line 23

def states_stores
  @states_stores
end

#states_stores_optionsObject



27
28
29
# File 'lib/state_store/extension.rb', line 27

def states_stores_options
  @states_stores_options
end