smash_the_state 1.4.4 → 1.5.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: 9a4407b73af1d296ca49dc0e0d112e3fd4a497d37e66cc97026bcf75835e8d48
4
- data.tar.gz: 19c36a89864c088ff0ff068768049dc68c798b57b3b074dd4cd4721f46386abb
3
+ metadata.gz: 9538187d0adbf668fd4cd35bfb97e04591c6d70c758109486251cf7ac66df1d7
4
+ data.tar.gz: 99eac2a8a14d9d30884b07171dab596ed8fd6ad662127cb3678e32a3a3041d3a
5
5
  SHA512:
6
- metadata.gz: 3054575953e6e59b15a454609698b8346a6a2fab75ee578c94029b895e03568ed0af214db70cd283c7db0eb97954a41d752d8ed4b18898282940a01534969b49
7
- data.tar.gz: b08cde0d76694574172be59467ffe790013aaa462664182345fb494d84976837102db57c60ba74e0753cda7c1b7925fa85adef77fae15e2eefecf5bb0903b41e
6
+ metadata.gz: 2cd363ad82626e3874e94c2c1a58fe41e6b44ce8cdb5260975f1e2132b3fde84cd4b5fdbd994ee374aeaed65dc40bca9c6f6a8bd4fb9f32829b58024657c6f5f
7
+ data.tar.gz: d23d8b91270cfdb27eb32e5faad64776c7da6f2b894d65a7b18e9ca7b6c04e87907555ff86b9b7666032a22cf0ad85452c4dffc709a0fc0d42e2f841259d667a
data/README.md CHANGED
@@ -127,7 +127,7 @@ Let's say you have two database types: `WhiskeyDB` and `AbsintheDB`, each of whi
127
127
 
128
128
  ``` ruby
129
129
  class WhiskeyDBCreateMiddleware
130
- def create_environment(state)
130
+ def self.create_environment(state)
131
131
  # do whiskey things
132
132
  end
133
133
  end
@@ -136,7 +136,7 @@ end
136
136
 
137
137
  ``` ruby
138
138
  class AbsintheDBCreateMiddleware
139
- def create_environment(state)
139
+ def self.create_environment(state)
140
140
  # do absinthe things
141
141
  end
142
142
  end
@@ -134,9 +134,7 @@ module SmashTheState
134
134
  def make_original_state(state)
135
135
  return dynamic_schema_step.implementation.call(state, state, run_options) if dynamic_schema?
136
136
 
137
- state.
138
- dup.
139
- freeze # don't allow any modifications to the original state
137
+ state.dup
140
138
  end
141
139
 
142
140
  def run_steps(steps_to_run, state)
@@ -18,8 +18,8 @@ module SmashTheState
18
18
  attr_accessor :representer
19
19
 
20
20
  def build(params = nil, &block)
21
- Class.new(self).tap do |k|
22
- k.class_exec(params, &block)
21
+ Class.new(self) do
22
+ class_exec(params, &block)
23
23
  end
24
24
  end
25
25
 
@@ -29,7 +29,7 @@ module SmashTheState
29
29
  def schema(key, options = {}, &block)
30
30
  attribute key,
31
31
  :state_for_smashing,
32
- options.merge(
32
+ **options.merge(
33
33
  # allow for schemas to be provided inline *or* as a reference to a
34
34
  # type definition
35
35
  schema: attribute_options_to_ref_block(options) || block
@@ -39,19 +39,19 @@ module SmashTheState
39
39
  # for ActiveModel states we will treat the block as a collection of ActiveModel
40
40
  # validator directives
41
41
  def eval_validation_directives_block(state, &block)
42
- state.tap do |s|
43
- # each validate block should be a "fresh start" and not interfere with the
44
- # previous blocks
45
- s.class.clear_validators!
46
- s.class_eval(&block)
47
- s.validate || invalid!(s)
48
- end
42
+ # each validate block should be a "fresh start" and not interfere with the
43
+ # previous blocks
44
+ state.singleton_class.clear_validators!
45
+ state.singleton_class.class_eval(&block)
46
+
47
+ state.validate || invalid!(state)
48
+ state
49
49
  end
50
50
 
51
51
  def extend_validation_directives_block(state, &block)
52
- state.tap do |s|
53
- s.class_eval(&block)
54
- end
52
+ state.class_eval(&block)
53
+
54
+ state
55
55
  end
56
56
 
57
57
  # for non-ActiveModel states we will just evaluate the block as a validator
@@ -69,7 +69,7 @@ module SmashTheState
69
69
 
70
70
  # if a reference to a definition is provided, use the reference schema block
71
71
  def attribute_options_to_ref_block(options)
72
- options[:ref] && options[:ref].schema_block
72
+ options[:ref]&.schema_block
73
73
  end
74
74
 
75
75
  def invalid!(state)
@@ -16,10 +16,6 @@ module SmashTheState
16
16
  def side_effect_free?
17
17
  options[:side_effect_free] == true
18
18
  end
19
-
20
- def dup
21
- super
22
- end
23
19
  end
24
20
  end
25
21
  end
@@ -24,7 +24,7 @@ module SmashTheState
24
24
  # inheritance doesn't work with class attr_readers, this method is provided to
25
25
  # bootstrap an operation as a continuation of a "prelude" operation
26
26
  def continues_from(prelude)
27
- @state_class = prelude.state_class && prelude.state_class.dup
27
+ @state_class = prelude.state_class&.dup
28
28
  sequence.steps.concat prelude.sequence.steps
29
29
 
30
30
  # also make the dry run sequence continue
@@ -52,7 +52,7 @@ module SmashTheState
52
52
  sequence.override_step(step_name, options, &block)
53
53
 
54
54
  # also override the dry run step
55
- return if dry_run_sequence.steps_for_name(step_name).length.zero?
55
+ return if dry_run_sequence.steps_for_name(step_name).empty?
56
56
 
57
57
  dry_run_sequence.override_step(step_name, options, &block)
58
58
  end
@@ -122,7 +122,7 @@ module SmashTheState
122
122
  # state class can be nil if the schema is never defined. that's ok. in that
123
123
  # situation it's up to the first step to produce the original state and we'll pass
124
124
  # the params themselves in
125
- state = state_class && state_class.new(params)
125
+ state = state_class&.new(params)
126
126
  sequence_to_run.call(state || params)
127
127
  end
128
128
  end
@@ -1,3 +1,3 @@
1
1
  module SmashTheState
2
- VERSION = "1.4.4".freeze
2
+ VERSION = "1.5.0".freeze
3
3
  end
@@ -78,12 +78,10 @@ describe SmashTheState::Operation::Sequence do
78
78
  context "without an error handler" do
79
79
  it "re-raises the Error exception" do
80
80
  expect do
81
- begin
82
- instance.call([])
83
- raise "should not hit this"
84
- rescue SmashTheState::Operation::Error => e
85
- expect(e.state).to eq([:foo])
86
- end
81
+ instance.call([])
82
+ raise "should not hit this"
83
+ rescue SmashTheState::Operation::Error => e
84
+ expect(e.state).to eq([:foo])
87
85
  end
88
86
  end
89
87
  end
@@ -156,16 +154,14 @@ describe SmashTheState::Operation::Sequence do
156
154
 
157
155
  context "when no step by the given name exists" do
158
156
  it "raises an exception" do
159
- begin
160
- instance.override_step :four do
161
- end
162
-
163
- raise "should not reach this"
164
- rescue SmashTheState::Operation::Sequence::BadOverride => e
165
- expect(
166
- e.to_s
167
- ).to eq("overriding step :four failed because it does not exist")
157
+ instance.override_step :four do
168
158
  end
159
+
160
+ raise "should not reach this"
161
+ rescue SmashTheState::Operation::Sequence::BadOverride => e
162
+ expect(
163
+ e.to_s
164
+ ).to eq("overriding step :four failed because it does not exist")
169
165
  end
170
166
  end
171
167
 
@@ -266,11 +262,10 @@ describe SmashTheState::Operation::Sequence do
266
262
  instance.add_middleware_step :extra_step
267
263
  end
268
264
 
269
- it "block receives both the state and frozen original state" do
265
+ it "block receives the state and original state" do
270
266
  instance.middleware_class_block = proc do |state, original_state|
271
267
  expect(state).to eq(baz: "bing")
272
268
  expect(original_state).to eq(foo: "bar")
273
- expect(original_state.frozen?).to eq(true)
274
269
  end
275
270
 
276
271
  instance.call(foo: "bar")
@@ -112,13 +112,11 @@ describe SmashTheState::Operation::State do
112
112
  let!(:instance) { built.new }
113
113
 
114
114
  it "calls the block" do
115
- begin
116
- SmashTheState::Operation::State.eval_custom_validator_block(instance) do |i|
117
- i.errors.add(:bread, "is moldy")
118
- end
119
- rescue SmashTheState::Operation::State::Invalid => e
120
- expect(e.state.errors[:bread]).to include("is moldy")
115
+ SmashTheState::Operation::State.eval_custom_validator_block(instance) do |i|
116
+ i.errors.add(:bread, "is moldy")
121
117
  end
118
+ rescue SmashTheState::Operation::State::Invalid => e
119
+ expect(e.state.errors[:bread]).to include("is moldy")
122
120
  end
123
121
 
124
122
  it "only raises an error for the current state" do
@@ -237,17 +237,17 @@ describe SmashTheState::Operation do
237
237
  context "with a custom dry run sequence block" do
238
238
  before do
239
239
  klass.step :step_one do |state, _original_state, run_options|
240
- state.name = state.name + " one " + run_options.to_json
240
+ state.name = "#{state.name} one #{run_options.to_json}"
241
241
  state
242
242
  end
243
243
 
244
244
  klass.step :step_two do |state|
245
- state.name = state.name + " two"
245
+ state.name = "#{state.name} two"
246
246
  state
247
247
  end
248
248
 
249
249
  klass.step :step_three do |state|
250
- state.name = state.name + " three"
250
+ state.name = "#{state.name} three"
251
251
  state
252
252
  end
253
253
 
@@ -257,7 +257,7 @@ describe SmashTheState::Operation do
257
257
 
258
258
  # we'll provide a custom implementation of this step
259
259
  step :step_two do |state|
260
- state.name = state.name + " custom"
260
+ state.name = "#{state.name} custom"
261
261
  state
262
262
  end
263
263
 
@@ -341,7 +341,7 @@ describe SmashTheState::Operation do
341
341
 
342
342
  context "when the policy permits" do
343
343
  it "newifies the policy class with the state, runs the method" do
344
- state = klass.call(current_user: current_user)
344
+ state = klass.call(current_user:)
345
345
  expect(state.name).to eq("allowed")
346
346
  end
347
347
  end
@@ -352,13 +352,11 @@ describe SmashTheState::Operation do
352
352
  end
353
353
 
354
354
  it "raises an exception, embeds the policy instance" do
355
- begin
356
- klass.call(current_user: current_user)
357
- raise "should not hit this"
358
- rescue SmashTheState::Operation::NotAuthorized => e
359
- expect(e.policy_instance).to be_a(@policy_klass)
360
- expect(e.policy_instance.user).to eq(current_user)
361
- end
355
+ klass.call(current_user:)
356
+ raise "should not hit this"
357
+ rescue SmashTheState::Operation::NotAuthorized => e
358
+ expect(e.policy_instance).to be_a(@policy_klass)
359
+ expect(e.policy_instance.user).to eq(current_user)
362
360
  end
363
361
  end
364
362
  end
@@ -434,7 +432,7 @@ describe SmashTheState::Operation do
434
432
  context "with a validation step" do
435
433
  before do
436
434
  klass.step :run_this do |state|
437
- state.name = state.name + " People"
435
+ state.name = "#{state.name} People"
438
436
  state
439
437
  end
440
438
 
@@ -448,7 +446,7 @@ describe SmashTheState::Operation do
448
446
  end
449
447
 
450
448
  klass.step :safe, side_effect_free: true do |state|
451
- state.name = state.name + " are nice"
449
+ state.name = "#{state.name} are nice"
452
450
  state
453
451
  end
454
452
  end
@@ -468,7 +466,7 @@ describe SmashTheState::Operation do
468
466
  context "with no validation step" do
469
467
  before do
470
468
  klass.step :run_this, side_effect_free: true do |state|
471
- state.name = state.name + " People"
469
+ state.name = "#{state.name} People"
472
470
  state
473
471
  end
474
472
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smash_the_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Connor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-12 00:00:00.000000000 Z
11
+ date: 2023-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_attributes
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.0
19
+ version: '1.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: 1.2.0
26
+ version: '1.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: 6.0.3.1
33
+ version: 6.0.0
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: 6.0.3.1
40
+ version: 6.0.0
41
41
  description: ''
42
42
  email:
43
43
  - dan@danconnor.com
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.1.4
86
+ rubygems_version: 3.3.26
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: A useful utility for transforming state that provides step sequencing, middleware,