Module: SimpleStates::ClassMethods
- Defined in:
- lib/simple_states.rb
Instance Method Summary collapse
- #add_states(*states) ⇒ Object
- #allocate ⇒ Object
- #event(name, options = {}) ⇒ Object
- #new ⇒ Object
- #states(*args) ⇒ Object
Instance Method Details
#add_states(*states) ⇒ Object
42 43 44 |
# File 'lib/simple_states.rb', line 42 def add_states(*states) self.state_names = (self.state_names || []).concat(states.compact.map(&:to_sym)).uniq end |
#allocate ⇒ Object
28 29 30 |
# File 'lib/simple_states.rb', line 28 def allocate super.tap { |object| States.init(object) } end |
#event(name, options = {}) ⇒ Object
46 47 48 49 |
# File 'lib/simple_states.rb', line 46 def event(name, = {}) add_states([:to], *[:from]) self.events += [Event.new(name, )] end |
#new ⇒ Object
24 25 26 |
# File 'lib/simple_states.rb', line 24 def new(*) super.tap { |object| States.init(object) } end |
#states(*args) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/simple_states.rb', line 32 def states(*args) if args.empty? self.state_names ||= add_states(self.initial_state) else = args.last.is_a?(Hash) ? args.pop : {} self.initial_state = [:initial].to_sym if .key?(:initial) add_states(*[self.initial_state].concat(args)) end end |