Module: StatePattern::ClassMethods
- Defined in:
- lib/state_pattern.rb
Instance Method Summary collapse
- #add_state_class(state_class) ⇒ Object
- #add_states(*state_classes) ⇒ Object
- #delegate_all_state_events ⇒ Object
- #initial_state_class ⇒ Object
- #set_initial_state(state_class) ⇒ Object
- #state_classes ⇒ Object
- #state_methods ⇒ Object
- #transitions_hash ⇒ Object
- #valid_transitions(transitions_hash) ⇒ Object
Instance Method Details
#add_state_class(state_class) ⇒ Object
28 29 30 |
# File 'lib/state_pattern.rb', line 28 def add_state_class(state_class) state_classes << state_class end |
#add_states(*state_classes) ⇒ Object
22 23 24 25 26 |
# File 'lib/state_pattern.rb', line 22 def add_states(*state_classes) state_classes.each do |state_class| add_state_class(state_class) end end |
#delegate_all_state_events ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/state_pattern.rb', line 45 def delegate_all_state_events state_methods.each do |state_method| define_method state_method do |*args| delegate_to_event(state_method) end end end |
#initial_state_class ⇒ Object
14 15 16 |
# File 'lib/state_pattern.rb', line 14 def initial_state_class @initial_state_class end |
#set_initial_state(state_class) ⇒ Object
18 19 20 |
# File 'lib/state_pattern.rb', line 18 def set_initial_state(state_class) @initial_state_class = state_class end |
#state_classes ⇒ Object
10 11 12 |
# File 'lib/state_pattern.rb', line 10 def state_classes @state_classes ||= [] end |
#state_methods ⇒ Object
53 54 55 |
# File 'lib/state_pattern.rb', line 53 def state_methods state_classes.map{|state_class| state_class.public_instance_methods(false)}.flatten.uniq end |
#transitions_hash ⇒ Object
41 42 43 |
# File 'lib/state_pattern.rb', line 41 def transitions_hash @transitions_hash end |
#valid_transitions(transitions_hash) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/state_pattern.rb', line 32 def valid_transitions(transitions_hash) @transitions_hash = transitions_hash @transitions_hash.each do |key, value| if !value.respond_to?(:to_ary) @transitions_hash[key] = [value] end end end |