Class: SimpleStates::States
- Inherits:
-
Module
- Object
- Module
- SimpleStates::States
- Defined in:
- lib/simple_states/states.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(events) ⇒ States
constructor
A new instance of States.
Constructor Details
#initialize(events) ⇒ States
Returns a new instance of States.
17 18 19 20 |
# File 'lib/simple_states/states.rb', line 17 def initialize(events) @events = merge_events(events) setup end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
15 16 17 |
# File 'lib/simple_states/states.rb', line 15 def events @events end |
Class Method Details
.init(object) ⇒ Object
4 5 6 7 |
# File 'lib/simple_states/states.rb', line 4 def init(object) object.singleton_class.send(:include, proxy_for(object.class)) object.init_state unless object.singleton_class.respond_to?(:after_initialize) end |
.proxy_for(klass) ⇒ Object
9 10 11 12 |
# File 'lib/simple_states/states.rb', line 9 def proxy_for(klass) args = [:StatesProxy].concat(klass.method(:const_defined?).arity != 1 ? [false] : []) klass.const_defined?(*args) ? klass::StatesProxy : klass.const_set(:StatesProxy, new(klass.events)) end |