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 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
@@ -14,4 +14,6 @@ gemfile:
14
14
  matrix:
15
15
  exclude:
16
16
  - rvm: 1.8.7
17
- gemfile: gemfiles/ar40.gemfile
17
+ gemfile: gemfiles/ar40.gemfile
18
+ - rvm: 1.8.7
19
+ gemfile: gemfiles/ar41.gemfile
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:
@@ -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.20'
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'
@@ -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.12'
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'
@@ -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.13'
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'
@@ -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'
@@ -43,6 +43,7 @@ module Stator
43
43
 
44
44
  def validate_transition
45
45
  return unless self.state_changed?
46
+ return if @machine.skip_validations
46
47
 
47
48
  was = self.state_was
48
49
  is = self.state
@@ -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
 
@@ -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)
@@ -1,7 +1,7 @@
1
1
  module Stator
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- PATCH = 0
4
+ PATCH = 1
5
5
  PRERELEASE = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, PATCH, PRERELEASE].compact.join('.')
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.0
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-09-23 00:00:00.000000000 Z
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: 1.8.25
80
+ rubygems_version: 2.4.2
84
81
  signing_key:
85
- specification_version: 3
82
+ specification_version: 4
86
83
  summary: The simplest of ActiveRecord state machines
87
84
  test_files:
88
85
  - spec/model_spec.rb