stator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +3 -1
- data/README.md +8 -0
- data/gemfiles/ar30.gemfile +2 -2
- data/gemfiles/ar31.gemfile +2 -2
- data/gemfiles/ar32.gemfile +2 -2
- data/gemfiles/ar40.gemfile +2 -2
- data/gemfiles/ar41.gemfile +10 -0
- data/lib/stator/integration.rb +1 -0
- data/lib/stator/machine.rb +9 -0
- data/lib/stator/model.rb +7 -1
- data/lib/stator/transition.rb +2 -0
- data/lib/stator/version.rb +1 -1
- data/spec/model_spec.rb +15 -0
- metadata +6 -9
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2Q2ZmJmM2E3MzUxYjBjMmJkMWU0MDdkMThiMDE0Y2ZhZThhNzI0Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODNkNWJmOTBkZDlmYzhkYmY3NTUxNjA0MTlkMDYyMTlkZjRlOTk4ZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWM3YTg4OWNhN2E1MTg4YTJjNTYxZWIzNWNmZTk2NTI0ODg0ZjAzYzM3Y2Uw
|
10
|
+
Mzc0YWI0Nzk0NmI5ZmZiYThkZmJiNDlmNGU5ZWZlYzVmZWNhZjJiODk4ZGRi
|
11
|
+
MDdhY2Y1MGU3OWNmNGFiNDVhMzcyMjU3ZmUyZmY3MDQ0ZTFjNjY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTFhNDIyMDE5ZGNkOTlhN2EyNTUxMWIyZjgyNTU0NWRhMmVhZDkzZjJkMDEx
|
14
|
+
N2RmZTliMTZkY2NlNmE4YTAxZGE0ZDZiODMxYzNhZmU3OTk4YjI1NzQzOTEy
|
15
|
+
M2JhNjc2NThlZmY3MzRkOTIyMjkwYzhjZGY4YTRmNTlhMzFkMjg=
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -147,6 +147,14 @@ If you need to access the state machine directly, you can do so via the class:
|
|
147
147
|
User._stator(namespace)
|
148
148
|
```
|
149
149
|
|
150
|
+
You can opt out of state transition validation by using the `without_state_transition_validations` method:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
user.without_state_transition_validations do
|
154
|
+
user.activate!
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
150
158
|
#### Aliasing
|
151
159
|
|
152
160
|
It's a really common case to have a set of states evaluated as a single concept. For example, many apps have a concept of "active" users. You generally see something like this:
|
data/gemfiles/ar30.gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in stator.gemspec
|
4
|
-
gem 'activerecord', '3.0.
|
4
|
+
gem 'activerecord', '~> 3.0.0'
|
5
5
|
|
6
6
|
gemspec :path => '../'
|
7
7
|
|
8
8
|
gem 'rake'
|
9
9
|
gem 'activerecord-nulldb-adapter', :require => false
|
10
|
-
gem 'rspec'
|
10
|
+
gem 'rspec'
|
data/gemfiles/ar31.gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in stator.gemspec
|
4
|
-
gem 'activerecord', '3.1.
|
4
|
+
gem 'activerecord', '~> 3.1.0'
|
5
5
|
|
6
6
|
gemspec :path => '../'
|
7
7
|
|
8
8
|
gem 'rake'
|
9
9
|
gem 'activerecord-nulldb-adapter', :require => false
|
10
|
-
gem 'rspec'
|
10
|
+
gem 'rspec'
|
data/gemfiles/ar32.gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in stator.gemspec
|
4
|
-
gem 'activerecord', '3.2.
|
4
|
+
gem 'activerecord', '~> 3.2.0'
|
5
5
|
|
6
6
|
gemspec :path => '../'
|
7
7
|
|
8
8
|
gem 'rake'
|
9
9
|
gem 'activerecord-nulldb-adapter', :require => false
|
10
|
-
gem 'rspec'
|
10
|
+
gem 'rspec'
|
data/gemfiles/ar40.gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in stator.gemspec
|
4
|
-
gem 'activerecord', '4.0.0'
|
4
|
+
gem 'activerecord', '~> 4.0.0'
|
5
5
|
|
6
6
|
gemspec :path => '../'
|
7
7
|
|
8
8
|
gem 'rake'
|
9
9
|
gem 'activerecord-nulldb-adapter', :require => false, :github => 'nulldb/nulldb', :ref => 'ffc7dae4697c6b9fb15bed9edca3acb1f00eb5f0'
|
10
|
-
gem 'rspec'
|
10
|
+
gem 'rspec'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in stator.gemspec
|
4
|
+
gem 'activerecord', '~> 4.1.0'
|
5
|
+
|
6
|
+
gemspec :path => '../'
|
7
|
+
|
8
|
+
gem 'rake'
|
9
|
+
gem 'activerecord-nulldb-adapter', :require => false, :github => 'nulldb/nulldb', :ref => 'ffc7dae4697c6b9fb15bed9edca3acb1f00eb5f0'
|
10
|
+
gem 'rspec'
|
data/lib/stator/integration.rb
CHANGED
data/lib/stator/machine.rb
CHANGED
@@ -7,6 +7,7 @@ module Stator
|
|
7
7
|
attr_reader :transitions
|
8
8
|
attr_reader :states
|
9
9
|
attr_reader :namespace
|
10
|
+
attr_reader :skip_validations
|
10
11
|
|
11
12
|
|
12
13
|
def initialize(klass, options = {})
|
@@ -85,6 +86,14 @@ module Stator
|
|
85
86
|
@class_name.constantize
|
86
87
|
end
|
87
88
|
|
89
|
+
def without_validation
|
90
|
+
was = @skip_validations
|
91
|
+
@skip_validations = true
|
92
|
+
yield
|
93
|
+
ensure
|
94
|
+
@skip_validations = was
|
95
|
+
end
|
96
|
+
|
88
97
|
protected
|
89
98
|
|
90
99
|
def verify_transition_validity(transition)
|
data/lib/stator/model.rb
CHANGED
@@ -54,6 +54,12 @@ module Stator
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
def without_state_transition_validations(namespace = '')
|
58
|
+
self._stator(namespace).without_validation do
|
59
|
+
yield
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
57
63
|
protected
|
58
64
|
|
59
65
|
def _stator_validate_transition
|
@@ -62,7 +68,7 @@ module Stator
|
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
65
|
-
def _stator(namespace)
|
71
|
+
def _stator(namespace = '')
|
66
72
|
self.class._stator(namespace)
|
67
73
|
end
|
68
74
|
|
data/lib/stator/transition.rb
CHANGED
@@ -106,6 +106,8 @@ module Stator
|
|
106
106
|
|
107
107
|
def can_#{@full_name}?
|
108
108
|
machine = self._stator(#{@namespace.inspect})
|
109
|
+
return true if machine.skip_validations
|
110
|
+
|
109
111
|
integration = machine.integration(self)
|
110
112
|
transition = machine.transitions.detect{|t| t.full_name.to_s == #{@full_name.inspect}.to_s }
|
111
113
|
transition.can?(integration.state)
|
data/lib/stator/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -126,6 +126,21 @@ describe Stator::Model do
|
|
126
126
|
f.state.should eql('constructed')
|
127
127
|
end
|
128
128
|
|
129
|
+
it 'should allow any transition if validations are opted out of' do
|
130
|
+
u = User.new
|
131
|
+
u.email = 'doug@example.com'
|
132
|
+
|
133
|
+
u.can_hyperactivate?.should eql(false)
|
134
|
+
u.hyperactivate.should eql(false)
|
135
|
+
|
136
|
+
u.state.should eql('pending')
|
137
|
+
|
138
|
+
u.without_state_transition_validations do
|
139
|
+
u.can_hyperactivate?.should eql(true)
|
140
|
+
u.hyperactivate.should eql(true)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
129
144
|
describe 'helper methods' do
|
130
145
|
|
131
146
|
it 'should answer the question of whether the state is currently the one invoked' do
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mike Nelson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -48,6 +45,7 @@ files:
|
|
48
45
|
- gemfiles/ar31.gemfile
|
49
46
|
- gemfiles/ar32.gemfile
|
50
47
|
- gemfiles/ar40.gemfile
|
48
|
+
- gemfiles/ar41.gemfile
|
51
49
|
- lib/stator.rb
|
52
50
|
- lib/stator/alias.rb
|
53
51
|
- lib/stator/integration.rb
|
@@ -62,27 +60,26 @@ files:
|
|
62
60
|
- stator.gemspec
|
63
61
|
homepage: https://www.github.com/mnelson/stator
|
64
62
|
licenses: []
|
63
|
+
metadata: {}
|
65
64
|
post_install_message:
|
66
65
|
rdoc_options: []
|
67
66
|
require_paths:
|
68
67
|
- lib
|
69
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
69
|
requirements:
|
72
70
|
- - ! '>='
|
73
71
|
- !ruby/object:Gem::Version
|
74
72
|
version: '0'
|
75
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
74
|
requirements:
|
78
75
|
- - ! '>='
|
79
76
|
- !ruby/object:Gem::Version
|
80
77
|
version: '0'
|
81
78
|
requirements: []
|
82
79
|
rubyforge_project:
|
83
|
-
rubygems_version:
|
80
|
+
rubygems_version: 2.4.2
|
84
81
|
signing_key:
|
85
|
-
specification_version:
|
82
|
+
specification_version: 4
|
86
83
|
summary: The simplest of ActiveRecord state machines
|
87
84
|
test_files:
|
88
85
|
- spec/model_spec.rb
|