statesman 1.0.0.beta1 → 1.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +8 -12
- data/lib/statesman/adapters/{active_record_model.rb → active_record_queries.rb} +1 -1
- data/lib/statesman/version.rb +1 -1
- data/lib/statesman.rb +2 -2
- data/spec/statesman/adapters/{active_record_model_spec.rb → active_record_queries_spec.rb} +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5acbb511b8785176c360bef3aa219e6032f04cea
|
4
|
+
data.tar.gz: a3e42e31f916ce396904a0e5dc7a687643ee124a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df0ba4a9e60e6f9eab79a028d580f59f19b95cf8de5a95ca27b496f0ead46634b12160c3bb6984eee5ed4b9d763360a71172cee48159d15bb42987902291828
|
7
|
+
data.tar.gz: 81796ee3bae3a594dedb93ad2c9d45793e955ca96501a3221de013d74d9ba8816889c7a219071b4660e2a8aaf9301f2f7c6759727d366e4d792a53b595dd5197
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
## v1.0.0.
|
1
|
+
## v1.0.0.beta2 10 October 2014
|
2
|
+
*Breaking changes*
|
3
|
+
|
4
|
+
- Rename `ActiveRecordModel` to `ActiveRecordQueries`, to reflect the fact that it mixes in some helpful scopes, but is not required.
|
5
|
+
|
6
|
+
## v1.0.0.beta1 9 October 2014
|
2
7
|
*Breaking changes*
|
3
8
|
|
4
9
|
- Classes which include `ActiveRecordModel` must define an `initial_state` class method.
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ class OrderStateMachine
|
|
53
53
|
end
|
54
54
|
|
55
55
|
class Order < ActiveRecord::Base
|
56
|
-
include Statesman::Adapters::
|
56
|
+
include Statesman::Adapters::ActiveRecordQueries
|
57
57
|
|
58
58
|
has_many :order_transitions
|
59
59
|
|
@@ -66,6 +66,10 @@ class Order < ActiveRecord::Base
|
|
66
66
|
def self.transition_class
|
67
67
|
OrderTransition
|
68
68
|
end
|
69
|
+
|
70
|
+
def self.initial_state
|
71
|
+
:pending
|
72
|
+
end
|
69
73
|
end
|
70
74
|
|
71
75
|
class OrderTransition < ActiveRecord::Base
|
@@ -335,7 +339,7 @@ model and define `transition_class` and `initial_state` class methods:
|
|
335
339
|
|
336
340
|
```ruby
|
337
341
|
class Order < ActiveRecord::Base
|
338
|
-
include Statesman::Adapters::
|
342
|
+
include Statesman::Adapters::ActiveRecordQueries
|
339
343
|
|
340
344
|
private
|
341
345
|
|
@@ -357,16 +361,6 @@ Returns all models not currently in any of the supplied states. Prior to 1.0 thi
|
|
357
361
|
|
358
362
|
## Frequently Asked Questions
|
359
363
|
|
360
|
-
#### `Model.in_state` does not work before first transition
|
361
|
-
|
362
|
-
This is expected. State is modelled as a series of tranisitions so initially where there has been no transition, there is no explict state. At GoCardless we get around this by transitioning immediately after creation:
|
363
|
-
|
364
|
-
```ruby
|
365
|
-
after_create do
|
366
|
-
state_machine.transition_to! "pending"
|
367
|
-
end
|
368
|
-
```
|
369
|
-
|
370
364
|
#### Storing the state on the model object
|
371
365
|
|
372
366
|
If you wish to store the model state on the model directly, you can keep it up to date using an `after_transition` hook:
|
@@ -378,6 +372,8 @@ after_transition do |model, transition|
|
|
378
372
|
end
|
379
373
|
```
|
380
374
|
|
375
|
+
You could also use a calculated column or view in your database.
|
376
|
+
|
381
377
|
#### Accessing metadata from the last transition
|
382
378
|
|
383
379
|
Given a field `foo` that was stored in the metadata, you can access it like so:
|
data/lib/statesman/version.rb
CHANGED
data/lib/statesman.rb
CHANGED
@@ -9,8 +9,8 @@ module Statesman
|
|
9
9
|
autoload :ActiveRecord, "statesman/adapters/active_record"
|
10
10
|
autoload :ActiveRecordTransition,
|
11
11
|
"statesman/adapters/active_record_transition"
|
12
|
-
autoload :
|
13
|
-
"statesman/adapters/
|
12
|
+
autoload :ActiveRecordQueries,
|
13
|
+
"statesman/adapters/active_record_queries"
|
14
14
|
autoload :Mongoid, "statesman/adapters/mongoid"
|
15
15
|
autoload :MongoidTransition,
|
16
16
|
"statesman/adapters/mongoid_transition"
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Statesman::Adapters::
|
3
|
+
describe Statesman::Adapters::ActiveRecordQueries do
|
4
4
|
before do
|
5
5
|
prepare_model_table
|
6
6
|
prepare_transitions_table
|
7
7
|
end
|
8
8
|
|
9
9
|
before do
|
10
|
-
MyActiveRecordModel.send(:include, Statesman::Adapters::
|
10
|
+
MyActiveRecordModel.send(:include, Statesman::Adapters::ActiveRecordQueries)
|
11
11
|
MyActiveRecordModel.class_eval do
|
12
12
|
def self.transition_class
|
13
13
|
MyActiveRecordModelTransition
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statesman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Marr
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -193,7 +193,7 @@ files:
|
|
193
193
|
- lib/generators/statesman/templates/update_migration.rb.erb
|
194
194
|
- lib/statesman.rb
|
195
195
|
- lib/statesman/adapters/active_record.rb
|
196
|
-
- lib/statesman/adapters/
|
196
|
+
- lib/statesman/adapters/active_record_queries.rb
|
197
197
|
- lib/statesman/adapters/active_record_transition.rb
|
198
198
|
- lib/statesman/adapters/memory.rb
|
199
199
|
- lib/statesman/adapters/memory_transition.rb
|
@@ -210,7 +210,7 @@ files:
|
|
210
210
|
- spec/generators/statesman/migration_generator_spec.rb
|
211
211
|
- spec/generators/statesman/mongoid_transition_generator_spec.rb
|
212
212
|
- spec/spec_helper.rb
|
213
|
-
- spec/statesman/adapters/
|
213
|
+
- spec/statesman/adapters/active_record_queries_spec.rb
|
214
214
|
- spec/statesman/adapters/active_record_spec.rb
|
215
215
|
- spec/statesman/adapters/active_record_transition_spec.rb
|
216
216
|
- spec/statesman/adapters/memory_spec.rb
|
@@ -254,7 +254,7 @@ test_files:
|
|
254
254
|
- spec/generators/statesman/migration_generator_spec.rb
|
255
255
|
- spec/generators/statesman/mongoid_transition_generator_spec.rb
|
256
256
|
- spec/spec_helper.rb
|
257
|
-
- spec/statesman/adapters/
|
257
|
+
- spec/statesman/adapters/active_record_queries_spec.rb
|
258
258
|
- spec/statesman/adapters/active_record_spec.rb
|
259
259
|
- spec/statesman/adapters/active_record_transition_spec.rb
|
260
260
|
- spec/statesman/adapters/memory_spec.rb
|