pathway 0.7.0 → 0.8.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
  SHA1:
3
- metadata.gz: 10f9020a8388d7f7aa7f4f321d506d98f2ce59ec
4
- data.tar.gz: a7d8dc64b79bf6a19f52f5cf78e59e0f9e9faae3
3
+ metadata.gz: 18bbd2169b9b1ce06075cb6b44ba3785f5853019
4
+ data.tar.gz: 6d94d279e070945bffd59a23e20a4fbcf7a90219
5
5
  SHA512:
6
- metadata.gz: 9a0cb43cf90894f6c9f19692bc33eca3ee6eaf6dd834d88ebbee0261447c70a7f0f96a3f05098d6339561de34fb65393708529c713b383b31779738c79748d50
7
- data.tar.gz: 9c66e74dafc09384a8d2f06df57490206a8e5e9cf756765085fd4b56353a498a388eedd2abc4d03c8d4d997ac1ba284e74feb087d77bce67a800c6ede04cad5b
6
+ metadata.gz: '095c9f17c4484b2dd8da4d9d98ac37e41845b4493c703cb98704bf2523f5cd14656528dd162f47cda8d4ea940e53861c351d1b9f7888c0589a36f562c7fa1bb8'
7
+ data.tar.gz: 5213eb74c0080d343f9e52a6f805101cd5a4052e7bd7dbad3d83fa01f4b15e502fcf212b2a8e1d666d41af8d6449cd15cbc2c78b2f363dab41fd947d32c13204
@@ -1,7 +1,15 @@
1
+ ## [0.8.0] - 2018-10-01
2
+ ### Changed
3
+ - Added support for `dry-validation` 0.12.x
4
+ - Renamed DSL method `sequence` to `around`. Keep `sequence` as an alias although, it may be deprecated on a future mayor release.
5
+ - Renamed DSL method `guard` to `if_true`. Keep `guard` as an alias, although it may be deprecated on a future mayor release.
6
+ - Added DSL method `if_false`, which behaves like `if_true` but checks the passed predicate is false instead.
7
+ - Moved `Responder` class inside the `responder` plugin module.
8
+
1
9
  ## [0.7.0] - 2018-09-25
2
10
  ### Changed
3
11
  - `sequel_models` plugin now automatically adds an optional context parameter to preload the model and avoid hitting the db on `:fetch_model` when the model is already available.
4
- - Add `:set_context_param` option for `sequel_models` plugin to prevent adding the context parameter to preload the model into the context.
12
+ - Added `:set_context_param` option for `sequel_models` plugin to prevent trying to preload the model from the context.
5
13
  - Allow `authorization` block to take multiple parameters on `simple_auth` plugin.
6
14
 
7
15
  ## [0.6.2] - 2018-05-19
@@ -10,22 +18,22 @@
10
18
 
11
19
  ## [0.6.1] - 2018-03-16
12
20
  ### Changed
13
- - Update default error message for `:fetch_model` step, at `sequel_models` plugin, to indicate the model's name
14
- - Add `:error_message` option for `sequel_models` plugin initializer to set the default error message
15
- - Add `:error_message` option for `:fetch_model` step to override the default error message
21
+ - Updated default error message for `:fetch_model` step, at `sequel_models` plugin, to indicate the model's name
22
+ - Added `:error_message` option for `sequel_models` plugin initializer to set the default error message
23
+ - Added `:error_message` option for `:fetch_model` step to override the default error message
16
24
 
17
25
  ## [0.6.0] - 2018-03-01
18
26
  ### Changed
19
- - Replace unmaintained `inflecto` gem with `dry-inflector`
27
+ - Replaced unmaintained `inflecto` gem with `dry-inflector`
20
28
 
21
29
  ## [0.5.1] - 2017-12-18
22
30
  ### Changed
23
- - Change behavior for `:fetch_model` step option `search_by:` to override both the search column and the input key (combine it with `using:` if you need a different value for the input key as well)
31
+ - Changed behavior for `:fetch_model` step option `search_by:` to override both the search column and the input key (combine it with `using:` if you need a different value for the input key as well)
24
32
  - `:fetch_model` step will no longer hit the database if the input key is nil and just return a `:not_found` error instead
25
33
 
26
34
  ## [0.5.0] - 2017-11-06
27
35
  ### Changed
28
- - Change base class for `Pathway::Error` from `StandardError` to `Object`
36
+ - Changed base class for `Pathway::Error` from `StandardError` to `Object`
29
37
 
30
38
  ## [0.4.0] - 2017-10-31
31
39
  ### Changed
data/README.md CHANGED
@@ -385,7 +385,7 @@ class CreateNugget < Pathway::Operation
385
385
  context :user_name
386
386
 
387
387
  form do
388
- configure { options :user_name }
388
+ configure { option :user_name }
389
389
 
390
390
  required(:owner).filled(:str?, :eql?: user_name)
391
391
  required(:price).filled(:int?)
@@ -411,7 +411,7 @@ class CreateNugget < Pathway::Operation
411
411
  context :current_user_name
412
412
 
413
413
  form do
414
- configure { options :user_name }
414
+ configure { option :user_name }
415
415
 
416
416
  required(:owner).filled(:str?, :eql?: user_name)
417
417
  required(:price).filled(:int?)
@@ -621,7 +621,7 @@ module Pathway
621
621
  end
622
622
  end
623
623
 
624
- sequence(transactional_seq, &steps)
624
+ around(transactional_seq, &steps)
625
625
  end
626
626
  end
627
627
 
@@ -655,9 +655,9 @@ Let's now examine the `fetch_model` step body, is not really that much different
655
655
 
656
656
  We finally see a `DSLMethods` module defined to extend the process DSL.
657
657
  For this plugin we'll define a way to group steps within an `ActiveRecord` transaction, much in the same way the `:sequel_models` plugin already does for `Sequel`.
658
- To this end we define a `transaction` method to expect a steps block and pass it down to the `sequence` helper below which expects a callable (like a `Proc`) and a step list block. As you can see the lambda we pass on the first parameter is the one that makes sure the steps are being run inside a transaction and to abort the transaction if the intermediate result is a failure.
658
+ To this end we define a `transaction` method to expect a steps block and pass it down to the `around` helper below which expects a callable (like a `Proc`) and a step list block. As you can see the lambda we pass on the first parameter is the one that makes sure the steps are being run inside a transaction and to abort the transaction if the intermediate result is a failure.
659
659
 
660
- The `sequence` method is a low level tool available to help extending the process DSL and it may seem a bit daunting at first glance but it usage is quite simple, the block is just a step list like the ones we find inside the `process` call; and the parameter is a callable (usually a lambda), that will take 2 arguments, an object from which we can run the step list by invoking `call` (and is the only thing it can do), and the current state. From here we can examine the state and decide upon whether to run the steps, how many times (if any) or run some code before and/or after doing so, like what we need to do in our example to surround the steps within a DB transaction.
660
+ The `around` method is a low level tool available to help extending the process DSL and it may seem a bit daunting at first glance but it usage is quite simple, the block is just a step list like the ones we find inside the `process` call; and the parameter is a callable (usually a lambda), that will take 2 arguments, an object from which we can run the step list by invoking `call` (and is the only thing it can do), and the current state. From here we can examine the state and decide upon whether to run the steps, how many times (if any) or run some code before and/or after doing so, like what we need to do in our example to surround the steps within a DB transaction.
661
661
 
662
662
  ### Testing tools
663
663
 
@@ -153,20 +153,28 @@ module Pathway
153
153
  @result = @result.then(bl)
154
154
  end
155
155
 
156
- def sequence(steps_wrapper, &steps)
156
+ def around(wrapper, &steps)
157
157
  @result.then do |state|
158
158
  seq = -> { @result = dup.run(&steps) }
159
- _callable(steps_wrapper).call(seq, state)
159
+ _callable(wrapper).call(seq, state)
160
160
  end
161
161
  end
162
162
 
163
- def guard(cond, &steps)
163
+ def if_true(cond, &steps)
164
164
  cond = _callable(cond)
165
- sequence(-> seq, state {
165
+ around(-> seq, state {
166
166
  seq.call if cond.call(state)
167
167
  }, &steps)
168
168
  end
169
169
 
170
+ def if_false(cond, &steps)
171
+ cond = _callable(cond)
172
+ if_true(-> state { !cond.call(state) }, &steps)
173
+ end
174
+
175
+ alias_method :sequence, :around
176
+ alias_method :guard, :if_true
177
+
170
178
  private
171
179
 
172
180
  def wrap(obj)
@@ -10,7 +10,7 @@ module Pathway
10
10
  def form(base = nil, **opts, &block)
11
11
  if block_given?
12
12
  base ||= _base_form
13
- self.form_class = Dry::Validation.Form(_form_class(base), _form_opts(opts), &block)
13
+ self.form_class = _block_definition(base, opts, &block)
14
14
  elsif base
15
15
  self.form_class = _form_class(base)
16
16
  else
@@ -37,7 +37,7 @@ module Pathway
37
37
  private
38
38
 
39
39
  def _base_form
40
- superclass.respond_to?(:form_class) ? superclass.form_class : Dry::Validation::Schema::Form
40
+ superclass.respond_to?(:form_class) ? superclass.form_class : DefaultFormClass
41
41
  end
42
42
 
43
43
  def _form_class(form)
@@ -72,9 +72,29 @@ module Pathway
72
72
  end
73
73
 
74
74
  def self.apply(operation, auto_wire_options: false)
75
- operation.form_class = Dry::Validation::Schema::Form
75
+ operation.form_class = DefaultFormClass
76
76
  operation.auto_wire_options = auto_wire_options
77
77
  end
78
+
79
+ if Dry::Validation::VERSION[/\A0\.(\d+).\d+\Z/, 1].to_i >= 12
80
+ DefaultFormClass = Dry::Validation::Schema::Params
81
+
82
+ module ClassMethods
83
+ private
84
+ def _block_definition(base, opts, &block)
85
+ Dry::Validation.Params(_form_class(base), _form_opts(opts), &block)
86
+ end
87
+ end
88
+ else
89
+ DefaultFormClass = Dry::Validation::Schema::Form
90
+
91
+ module ClassMethods
92
+ private
93
+ def _block_definition(base, opts, &block)
94
+ Dry::Validation.Form(_form_class(base), _form_opts(opts), &block)
95
+ end
96
+ end
97
+ end
78
98
  end
79
99
  end
80
100
  end
@@ -1,12 +1,44 @@
1
- require 'pathway/responder'
2
-
3
1
  module Pathway
4
2
  module Plugins
5
3
  module Responder
6
4
  module ClassMethods
7
5
  def call(ctx, *params, &bl)
8
6
  result = new(ctx).call(*params)
9
- block_given? ? Pathway::Responder.respond(result, &bl) : result
7
+ block_given? ? Responder.respond(result, &bl) : result
8
+ end
9
+ end
10
+
11
+ class Responder
12
+ def self.respond(result, &bl)
13
+ r = new(result, &bl)
14
+ r.respond
15
+ end
16
+
17
+ def initialize(result, &bl)
18
+ @result, @context, @fails = result, bl.binding.receiver, {}
19
+ instance_eval(&bl)
20
+ end
21
+
22
+ def success(&bl)
23
+ @ok = bl
24
+ end
25
+
26
+ def failure(type = nil, &bl)
27
+ if type.nil?
28
+ @fail_default = bl
29
+ else
30
+ @fails[type] = bl
31
+ end
32
+ end
33
+
34
+ def respond
35
+ if @result.success?
36
+ @context.instance_exec(@result.value, &@ok)
37
+ elsif Error === @result.error && fail_block = @fails[@result.error.type]
38
+ @context.instance_exec(@result.error, &fail_block)
39
+ else
40
+ @context.instance_exec(@result.error, &@fail_default)
41
+ end
10
42
  end
11
43
  end
12
44
  end
@@ -5,17 +5,17 @@ module Pathway
5
5
  module SequelModels
6
6
  module DSLMethods
7
7
  def transaction(&bl)
8
- sequence(-> seq, _ {
8
+ around(-> steps, _ {
9
9
  db.transaction(savepoint: true) do
10
- raise Sequel::Rollback if seq.call.failure?
10
+ raise Sequel::Rollback if steps.call.failure?
11
11
  end
12
12
  }, &bl)
13
13
  end
14
14
 
15
15
  def after_commit(&bl)
16
- sequence(-> seq, _ {
16
+ around(-> steps, _ {
17
17
  db.after_commit do
18
- seq.call
18
+ steps.call
19
19
  end
20
20
  }, &bl)
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module Pathway
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "dry-inflector", ">= 0.1.0"
27
27
  spec.add_dependency "contextualizer", "~> 0.0.4"
28
28
 
29
- spec.add_development_dependency "dry-validation", "~> 0.11.0"
29
+ spec.add_development_dependency "dry-validation", "~> 0.11"
30
30
  spec.add_development_dependency "bundler", ">= 1.14.0"
31
31
  spec.add_development_dependency "sequel", "~> 4.46.0"
32
32
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Herrero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-26 00:00:00.000000000 Z
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.11.0
47
+ version: '0.11'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.11.0
54
+ version: '0.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -174,7 +174,6 @@ files:
174
174
  - lib/pathway/plugins/responder.rb
175
175
  - lib/pathway/plugins/sequel_models.rb
176
176
  - lib/pathway/plugins/simple_auth.rb
177
- - lib/pathway/responder.rb
178
177
  - lib/pathway/result.rb
179
178
  - lib/pathway/rspec.rb
180
179
  - lib/pathway/rspec/matchers.rb
@@ -1,35 +0,0 @@
1
- module Pathway
2
- class Responder
3
- def self.respond(result, &bl)
4
- r = new(result, &bl)
5
- r.respond
6
- end
7
-
8
- def initialize(result, &bl)
9
- @result, @context, @fails = result, bl.binding.receiver, {}
10
- instance_eval(&bl)
11
- end
12
-
13
- def success(&bl)
14
- @ok = bl
15
- end
16
-
17
- def failure(type = nil, &bl)
18
- if type.nil?
19
- @fail_default = bl
20
- else
21
- @fails[type] = bl
22
- end
23
- end
24
-
25
- def respond
26
- if @result.success?
27
- @context.instance_exec(@result.value, &@ok)
28
- elsif Error === @result.error && fail_block = @fails[@result.error.type]
29
- @context.instance_exec(@result.error, &fail_block)
30
- else
31
- @context.instance_exec(@result.error, &@fail_default)
32
- end
33
- end
34
- end
35
- end