bstard 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTJmMDJmODEzNDNjOWNjODJlMDRmOWUyZWQ3N2I3NmY5NTA2ODk3Mw==
4
+ MDViNjIxNWEzZjM2N2RkZjM4ODRkZjljODgxNmI2ODlkZjVjMmM1MA==
5
5
  data.tar.gz: !binary |-
6
- NjI3YmVkYzhkYWE5YTA1MGY3MGYxN2ZlMjliNDY1YzNiODlkZTg2Mw==
6
+ MTkwYzViNzdlNmUwYWIyODEwODkyNTI5ZDY3ZTJkMmFmYzAyMTQxMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODM1MGQxYzkzNTQzYzkyNTEzYTE1MGY0YmI2MmY2OTUxMDUyOTg0YmU3MjM3
10
- NWVjM2E4YjVlMTZlMjMyZmRhOTMxZmI4MTQ3Y2Q5M2IzMTRlMDcxNzU0YmVi
11
- ZmM1ZTg4ZjQ3MzIzYjI5NTUzYWM3Zjc0ZGM3MjkxMTZiOTY1NTk=
9
+ NjViYjlmNTFmMjJjMTY0YzI5MGQzMDUxMjdjNzQ2NTc1MTczZWNiMjNlNjY4
10
+ ZDljODk0ZTUwODRmNDIzNGUyZWY3YWZlMGJlNGI0Y2U1ODMzYjJiN2JkMjUy
11
+ NTI1NWQ5MjExYmNiZWE5NzEzODhkZTg5NzFmNWZjMWE5Yjk3Njc=
12
12
  data.tar.gz: !binary |-
13
- ZGNlZDk4Njk5Zjg4OTkwMTg4Y2Q5ODI5Njc2YjZjNjgwNGQ4MTM2YjE2Mjkw
14
- MTI2YmMxZTA4Y2NkNGE2NzkyZjg1MjI4MDdhNzgwNjMyOTViZmNiODg2OWQy
15
- OWQzYzgxZTI4OWI1YjczMTI1OWIyYTZhZjE4NTg1NTI2ZGQ2NTc=
13
+ NDk4MmMxNDg5NjMwZjRhOTYzYWJmMjI1NDA2MmI5MjcxZmQ2ZWJmNzI5MGM1
14
+ NmY4YmRkNzkyNjY1NmExMWI1MGFhZjRmMDIwYjU3Y2FiNzk2OGMwMDk3MTc0
15
+ YjM0NGJiYTEwMTY1M2RhNTExMGQ3NmI5MDhiOWQyNTk0MTA4NGQ=
data/README.md CHANGED
@@ -32,7 +32,7 @@ Use `Bstard.define` to describe your state machine
32
32
 
33
33
  This defines a state machine that:
34
34
 
35
- - has __new__ __submitted__ and __deleted__ states
35
+ - has __new__, __submitted__ and __deleted__ states
36
36
  - responds to _submit_ and _delete_ events
37
37
  - has an initial state of __new__
38
38
  - transitions from __new__ to __submitted__ when triggered by the _submit_ event
@@ -95,7 +95,7 @@ Event callbacks are configured with `on`
95
95
  ``` ruby
96
96
  machine = Bstard.define do |fsm|
97
97
  # ...
98
- fsm.on :submit do |previous_state|
98
+ fsm.on :submit do |event, state, next_state|
99
99
  # code that needs to be run when :submit is triggered
100
100
  end
101
101
  end
@@ -106,7 +106,7 @@ State change callbacks are configured with `when`
106
106
  ``` ruby
107
107
  machine = Bstard.define do |fsm|
108
108
  # ...
109
- fsm.when :submitted do |previous_state|
109
+ fsm.when :submitted do |event, previous_state, state|
110
110
  # code that needs to run when state changes to :submitted
111
111
  end
112
112
  end
@@ -117,10 +117,10 @@ Use the symbol `:any` for event or state change callbacks that should by run whe
117
117
  ``` ruby
118
118
  machine = Bstard.define do |fsm|
119
119
  # ...
120
- fsm.on :any do |previous_state|
120
+ fsm.on :any do |event, state, next_state|
121
121
  # code that will run when any event is triggered
122
122
  end
123
- fsm.when :any do |previous_state|
123
+ fsm.when :any do |event, previous_state, state|
124
124
  # code that will run when after any state change
125
125
  end
126
126
  end
@@ -141,8 +141,8 @@ private
141
141
  fsm.initial status
142
142
  fsm.event :save, :new => :draft
143
143
  fsm.event :approve, :draft => :approved
144
- fsm.when :any do |prev_state|
145
- status = fsm.current_state
144
+ fsm.when :any do |event, prev_state, new_state|
145
+ status = new_state
146
146
  end
147
147
  end
148
148
  end
@@ -162,7 +162,7 @@ To run the tests, run `bundle exec rake test`.
162
162
 
163
163
  ## Contributing
164
164
 
165
- 1. Fork it ( https://github.com/[my-github-username]/bstard/fork )
165
+ 1. Fork it ( https://github.com/tonyheadford/bstard/fork )
166
166
  2. Create your feature branch (`git checkout -b my-new-feature`)
167
167
  3. Commit your changes (`git commit -am 'Add some feature'`)
168
168
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/bstard/fsm.rb CHANGED
@@ -59,12 +59,12 @@ class Bstard::Fsm
59
59
  transitions = @events[evt]
60
60
  raise Bstard::InvalidEvent.new("Unknown event <#{evt.to_s}>") if transitions.nil?
61
61
  new_state = transitions[current_state]
62
- raise Bstard::InvalidTransition.new("Cannot <#{evt.to_s}> from [#{current_state.to_s}]") if new_state.nil?
63
- @event_callbacks.fetch(evt.to_sym, []).concat(@event_callbacks.fetch(:any, [])).each { |c| c.call(current_state) }
64
62
  old_state = current_state
63
+ raise Bstard::InvalidTransition.new("Cannot <#{evt.to_s}> from [#{current_state.to_s}]") if new_state.nil?
64
+ @event_callbacks.fetch(evt.to_sym, []).concat(@event_callbacks.fetch(:any, [])).each { |c| c.call(evt, old_state, new_state) }
65
65
  @current_state = new_state
66
- @state_callbacks.fetch(current_state, []).concat(@state_callbacks.fetch(:any, [])).each { |c| c.call(old_state) }
67
- current_state
66
+ @state_callbacks.fetch(current_state, []).concat(@state_callbacks.fetch(:any, [])).each { |c| c.call(evt, old_state, new_state) }
67
+ new_state
68
68
  end
69
69
  end
70
70
  end
@@ -1,4 +1,4 @@
1
1
  module Bstard
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bstard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Headford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler