steady_state 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c80b6cce9dbf7702cdf8fd0d97c21794bcbc6a67c2ea688fcf5b150ee217df5a
4
- data.tar.gz: 67bc8bc9e117e55ac21b4dcba713dbf97627354c1997e906fbb317ef06b42ac6
3
+ metadata.gz: 7b7ad486ead2f7c864e7ba69d8525f7d6e72fbb220c7ebabf866802f1d7ad50b
4
+ data.tar.gz: f46001c070069cb44e77aa330170c1204626324c175d3c11ad8d11e21aaa3123
5
5
  SHA512:
6
- metadata.gz: 374352c07075b3ccb50c1c018e6b8e654ebcc84675d44e4024406dde923ba28699f58daf7b67f8161cff8ee41d9e4f75c77f59680f165b62e527787b7dd00e65
7
- data.tar.gz: 6d493623807a7332a1e3b96a9849d46b6a33d59e8405dbb935ef66de4d9b054b2c471ca8421feb7f75810a2aa6694b0173a64be694a69a31a6210de2232018b0
6
+ metadata.gz: ac41840168b5cf0aeba5ebf7ba80784fe164013ae2926a0939e713e1fb3d686d30c945c07a1b51a68cdcbfc00b13e9a2ccb2b12480f43a166b83d6bf4d7100ed
7
+ data.tar.gz: f74858d2bf2552e4603272f4cf82bee27bbc2930fe2eb1661e5717c34bfd011faf638caaea83b35d230672b07fca2e017a2965c611992aeac8f60d441735cee7
data/README.md CHANGED
@@ -231,6 +231,33 @@ As it stands, state history is not preserved, but it is still possible to get a
231
231
  material.state.previous_values # => ['solid']
232
232
  ```
233
233
 
234
+ ### The "States Getter"
235
+
236
+ A pluralized, class-level helper method can be used to access all possible state values:
237
+
238
+ ```ruby
239
+ Material.states # => ['solid', 'liquid', 'gas']
240
+ ```
241
+
242
+ These values respond to reflection methods like `may_become?`, `next_values`, and `previous_values`.
243
+
244
+ ```
245
+ Material.states.first.solid? # => true
246
+ Material.states[1].may_become?('solid') # => false
247
+ Material.states[1].next_values # => ['gas']
248
+ ```
249
+
250
+ The automatic definition of this class method can be disabled by passing `states_getter: false`:
251
+
252
+ ```ruby
253
+ steady_state :step, states_getter: false do
254
+ # ...
255
+ end
256
+
257
+ MyClass.steps # => NoMethodError
258
+ ```
259
+
260
+
234
261
  ### ActiveModel Support
235
262
 
236
263
  SteadyState is also available to classes that are not database-backed, as long as they include the `ActiveModel::Model` mixin:
data/Rakefile CHANGED
@@ -13,4 +13,14 @@ require 'rspec/core'
13
13
  require 'rspec/core/rake_task'
14
14
  RSpec::Core::RakeTask.new(:spec)
15
15
 
16
- task default: %i(rubocop spec)
16
+ def default_task
17
+ if ENV['APPRAISAL_INITIALIZED'] || ENV['CI']
18
+ %i(rubocop spec)
19
+ else
20
+ require 'appraisal'
21
+ Appraisal::Task.new
22
+ %i(appraisal)
23
+ end
24
+ end
25
+
26
+ task(:default).clear.enhance(default_task)
@@ -13,7 +13,7 @@ module SteadyState
13
13
  end
14
14
 
15
15
  class_methods do
16
- def steady_state(attr_name, predicates: true, states_getter: true, scopes: SteadyState.active_record?(self), &block) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/LineLength
16
+ def steady_state(attr_name, predicates: true, states_getter: true, scopes: SteadyState.active_record?(self), &block) # rubocop:disable Metrics/
17
17
  overrides = Module.new do
18
18
  define_method :"validate_#{attr_name}_transition_to" do |next_value|
19
19
  if public_send(attr_name).may_become?(next_value)
@@ -1,3 +1,3 @@
1
1
  module SteadyState
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -188,11 +188,11 @@ RSpec.describe SteadyState::Attribute do
188
188
  expect(subject.step.may_become?('step-1')).to eq false
189
189
  expect(subject.step.may_become?('step-2')).to eq true
190
190
  expect(subject.step.may_become?('cancelled')).to eq true
191
- expect(subject.step.next_values).to match_array(['cancelled', 'step-2'])
191
+ expect(subject.step.next_values).to match_array(%w(cancelled step-2))
192
192
  expect(subject.step.previous_values).to match_array([])
193
193
  expect { subject.step = 'cancelled' }.to change { subject.step }.from('step-1').to('cancelled')
194
194
  expect(subject.step.next_values).to match_array([])
195
- expect(subject.step.previous_values).to match_array(['step-1', 'step-2'])
195
+ expect(subject.step.previous_values).to match_array(%w(step-1 step-2))
196
196
  expect(subject).to be_valid
197
197
  end
198
198
 
@@ -200,7 +200,7 @@ RSpec.describe SteadyState::Attribute do
200
200
  expect(subject.step.may_become?('step-1')).to eq false
201
201
  expect(subject.step.may_become?('step-2')).to eq true
202
202
  expect(subject.step.may_become?('cancelled')).to eq true
203
- expect(subject.step.next_values).to match_array(['cancelled', 'step-2'])
203
+ expect(subject.step.next_values).to match_array(%w(cancelled step-2))
204
204
  expect(subject.step.previous_values).to match_array([])
205
205
  expect { subject.step = 'step-2' }.to change { subject.step }.from('step-1').to('step-2')
206
206
  expect(subject).to be_valid
@@ -212,7 +212,7 @@ RSpec.describe SteadyState::Attribute do
212
212
  expect(subject.step.previous_values).to match_array(['step-1'])
213
213
  expect { subject.step = 'cancelled' }.to change { subject.step }.from('step-2').to('cancelled')
214
214
  expect(subject.step.next_values).to match_array([])
215
- expect(subject.step.previous_values).to match_array(['step-1', 'step-2'])
215
+ expect(subject.step.previous_values).to match_array(%w(step-1 step-2))
216
216
  expect(subject).to be_valid
217
217
  end
218
218
  end
@@ -223,7 +223,7 @@ RSpec.describe SteadyState::Attribute do
223
223
  steady_state_class.module_eval do
224
224
  attr_accessor :door
225
225
 
226
- steady_state :door, options do
226
+ steady_state :door, **options do
227
227
  state 'open', default: true
228
228
  state 'closed', from: 'open'
229
229
  state 'locked', from: 'closed'
@@ -298,7 +298,7 @@ RSpec.describe SteadyState::Attribute do
298
298
  steady_state_class.module_eval do
299
299
  attr_accessor :car
300
300
 
301
- steady_state :car, options do
301
+ steady_state :car, **options do
302
302
  state 'driving', default: true
303
303
  state 'stopped', from: 'driving'
304
304
  state 'parked', from: 'stopped'
@@ -339,7 +339,7 @@ RSpec.describe SteadyState::Attribute do
339
339
  defined_scopes[name] ||= callable
340
340
  end
341
341
 
342
- steady_state :car, options do
342
+ steady_state :car, **options do
343
343
  state 'driving', default: true
344
344
  state 'stopped', from: 'driving'
345
345
  state 'parked', from: 'stopped'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steady_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Griffith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-10 00:00:00.000000000 Z
11
+ date: 2022-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -16,30 +16,30 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: '5.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: '5.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,21 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: betterlint
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,7 +81,7 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rubocop-betterment
84
+ name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -103,7 +117,8 @@ files:
103
117
  - spec/steady_state/attribute_spec.rb
104
118
  homepage:
105
119
  licenses: []
106
- metadata: {}
120
+ metadata:
121
+ rubygems_mfa_required: 'true'
107
122
  post_install_message:
108
123
  rdoc_options: []
109
124
  require_paths:
@@ -112,14 +127,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
127
  requirements:
113
128
  - - ">="
114
129
  - !ruby/object:Gem::Version
115
- version: '0'
130
+ version: 2.6.5
116
131
  required_rubygems_version: !ruby/object:Gem::Requirement
117
132
  requirements:
118
133
  - - ">="
119
134
  - !ruby/object:Gem::Version
120
135
  version: '0'
121
136
  requirements: []
122
- rubygems_version: 3.3.7
137
+ rubygems_version: 3.3.5
123
138
  signing_key:
124
139
  specification_version: 4
125
140
  summary: Minimalist state management via "an enum with guard rails"