pathway 0.12.1 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +3 -3
- data/lib/pathway/plugins/auto_deconstruct_state/ruby3.rb +1 -0
- data/lib/pathway/plugins/dry_validation/v0_11.rb +16 -6
- data/lib/pathway/plugins/dry_validation/v0_12.rb +16 -7
- data/lib/pathway/plugins/dry_validation/v1_0.rb +17 -8
- data/lib/pathway/version.rb +1 -1
- data/lib/pathway.rb +21 -1
- data/pathway.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83205585dcf796cdb4a5da8055163491d12586c48915e6d3ef7efe44ff6533f3
|
4
|
+
data.tar.gz: 1584cfc7dd38e44e14a810a96a658e29b5756aad62f36e1e69671a3c7631a656
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ade86174156600eb76a84af9ca96097eaa28a8760ba52f150fc9ed6c21ca5a69e387157cb7238c97990aa516ff712b98708941acf4885805e9bb4f8d85db2757
|
7
|
+
data.tar.gz: 855252fa3e0639a3d18bd1f0f10f7d379795516723da702c6201076a3767dc3a7f447191260d137f57716bf57915e654270a0209b6b3e36de9896e54faac7927
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## [0.12.3] - 2024-08-13
|
2
|
+
### Changed
|
3
|
+
- Renamed config option `:auto_wire_options` to `:auto_wire` at `:dry_validation` plugin
|
4
|
+
- Updated `Pathway::State#use` to accept block with postional parameters
|
5
|
+
- Updated `Pathway::State#use` to raise an `ArgumentError` exception on invalid arguments
|
6
|
+
### Added
|
7
|
+
- Provide alias `Pathway::State#use` to `Pathway::State#unwrap`
|
8
|
+
|
9
|
+
## [0.12.2] - 2024-08-06
|
10
|
+
### Added
|
11
|
+
- Add `Pathway::State#unwrap` and `Pathway::State#u` to access internal state
|
12
|
+
|
1
13
|
## [0.12.1] - 2024-06-23
|
2
14
|
### Added
|
3
15
|
- Add support for pattern matching on `Result`, `State` and `Error` instances
|
data/README.md
CHANGED
@@ -407,12 +407,12 @@ end
|
|
407
407
|
|
408
408
|
If you are familiar with `dry-validation` you probably know it provides a way to [inject options](https://dry-rb.org/gems/dry-validation/1.4/external-dependencies/) before calling the contract.
|
409
409
|
|
410
|
-
In those scenarios, you must either set the `
|
410
|
+
In those scenarios, you must either set the `auto_wire: true` plugin argument or specify how to map options from the execution state to the contract when calling `step :validate`.
|
411
411
|
Lets see and example for the first case:
|
412
412
|
|
413
413
|
```ruby
|
414
414
|
class CreateNugget < Pathway::Operation
|
415
|
-
plugin :dry_validation,
|
415
|
+
plugin :dry_validation, auto_wire: true
|
416
416
|
|
417
417
|
context :user_name
|
418
418
|
|
@@ -438,7 +438,7 @@ class CreateNugget < Pathway::Operation
|
|
438
438
|
end
|
439
439
|
```
|
440
440
|
|
441
|
-
Here the defined contract needs a `:user_name` option, so we tell the operation to grab the attribute with the same name from the state by activating `:
|
441
|
+
Here the defined contract needs a `:user_name` option, so we tell the operation to grab the attribute with the same name from the state by activating `:auto_wire`, afterwards, when the validation runs, the contract will already have the user name available.
|
442
442
|
|
443
443
|
Mind you, this option is `false` by default, so be sure to set it to `true` at `Pathway::Operation` if you'd rather have it enabled for all your operations.
|
444
444
|
|
@@ -8,6 +8,7 @@ module Pathway
|
|
8
8
|
|
9
9
|
def _callable(callable)
|
10
10
|
if callable.is_a?(Symbol) && @operation.respond_to?(callable, true) &&
|
11
|
+
@operation.method(callable).arity != 0 &&
|
11
12
|
@operation.method(callable).parameters.all? { _1 in [:key|:keyreq|:keyrest|:block,*] }
|
12
13
|
|
13
14
|
-> state { @operation.send(callable, **state) }
|
@@ -6,7 +6,10 @@ module Pathway
|
|
6
6
|
module V0_11
|
7
7
|
module ClassMethods
|
8
8
|
attr_reader :form_class, :form_options
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :auto_wire
|
10
|
+
|
11
|
+
alias_method :auto_wire_options, :auto_wire
|
12
|
+
alias_method :auto_wire_options=, :auto_wire=
|
10
13
|
|
11
14
|
def form(base = nil, **opts, &block)
|
12
15
|
if block_given?
|
@@ -32,7 +35,7 @@ module Pathway
|
|
32
35
|
def inherited(subclass)
|
33
36
|
super
|
34
37
|
subclass.form_class = form_class
|
35
|
-
subclass.
|
38
|
+
subclass.auto_wire = auto_wire
|
36
39
|
end
|
37
40
|
|
38
41
|
private
|
@@ -58,10 +61,11 @@ module Pathway
|
|
58
61
|
extend Forwardable
|
59
62
|
|
60
63
|
delegate %i[build_form form_options auto_wire_options] => 'self.class'
|
61
|
-
|
64
|
+
delegate %i[build_form form_options auto_wire_options auto_wire] => 'self.class'
|
65
|
+
alias_method :form, :build_form
|
62
66
|
|
63
67
|
def validate(state, with: nil)
|
64
|
-
if
|
68
|
+
if auto_wire && form_options.any?
|
65
69
|
with ||= form_options.zip(form_options).to_h
|
66
70
|
end
|
67
71
|
opts = Hash(with).map { |opt, key| [opt, state[key]] }.to_h
|
@@ -76,9 +80,15 @@ module Pathway
|
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
79
|
-
def self.apply(operation, auto_wire_options: false)
|
83
|
+
def self.apply(operation, auto_wire_options: (auto_wire_options_was_not_used=true; false), auto_wire: auto_wire_options)
|
84
|
+
#:nocov:
|
85
|
+
unless auto_wire_options_was_not_used
|
86
|
+
warn "[DEPRECATION] `auto_wire_options` is deprecated. Please use `auto_wire` instead"
|
87
|
+
end
|
88
|
+
#:nocov:
|
89
|
+
|
90
|
+
operation.auto_wire = auto_wire
|
80
91
|
operation.form_class = Dry::Validation::Schema::Form
|
81
|
-
operation.auto_wire_options = auto_wire_options
|
82
92
|
end
|
83
93
|
end
|
84
94
|
end
|
@@ -6,7 +6,10 @@ module Pathway
|
|
6
6
|
module V0_12
|
7
7
|
module ClassMethods
|
8
8
|
attr_reader :form_class, :form_options
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :auto_wire
|
10
|
+
|
11
|
+
alias_method :auto_wire_options, :auto_wire
|
12
|
+
alias_method :auto_wire_options=, :auto_wire=
|
10
13
|
|
11
14
|
def form(base = nil, **opts, &block)
|
12
15
|
if block_given?
|
@@ -32,7 +35,7 @@ module Pathway
|
|
32
35
|
def inherited(subclass)
|
33
36
|
super
|
34
37
|
subclass.form_class = form_class
|
35
|
-
subclass.
|
38
|
+
subclass.auto_wire = auto_wire
|
36
39
|
end
|
37
40
|
|
38
41
|
private
|
@@ -57,11 +60,11 @@ module Pathway
|
|
57
60
|
module InstanceMethods
|
58
61
|
extend Forwardable
|
59
62
|
|
60
|
-
delegate %i[build_form form_options auto_wire_options] => 'self.class'
|
61
|
-
|
63
|
+
delegate %i[build_form form_options auto_wire_options auto_wire] => 'self.class'
|
64
|
+
alias_method :form, :build_form
|
62
65
|
|
63
66
|
def validate(state, with: nil)
|
64
|
-
if
|
67
|
+
if auto_wire && form_options.any?
|
65
68
|
with ||= form_options.zip(form_options).to_h
|
66
69
|
end
|
67
70
|
opts = Hash(with).map { |opt, key| [opt, state[key]] }.to_h
|
@@ -76,9 +79,15 @@ module Pathway
|
|
76
79
|
end
|
77
80
|
end
|
78
81
|
|
79
|
-
def self.apply(operation, auto_wire_options: false)
|
82
|
+
def self.apply(operation, auto_wire_options: (auto_wire_options_was_not_used=true; false), auto_wire: auto_wire_options)
|
83
|
+
#:nocov:
|
84
|
+
unless auto_wire_options_was_not_used
|
85
|
+
warn "[DEPRECATION] `auto_wire_options` is deprecated. Please use `auto_wire` instead"
|
86
|
+
end
|
87
|
+
#:nocov:
|
88
|
+
|
89
|
+
operation.auto_wire = auto_wire
|
80
90
|
operation.form_class = Dry::Validation::Schema::Params
|
81
|
-
operation.auto_wire_options = auto_wire_options
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
@@ -6,7 +6,10 @@ module Pathway
|
|
6
6
|
module V1_0
|
7
7
|
module ClassMethods
|
8
8
|
attr_reader :contract_class, :contract_options
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :auto_wire
|
10
|
+
|
11
|
+
alias_method :auto_wire_options, :auto_wire
|
12
|
+
alias_method :auto_wire_options=, :auto_wire=
|
10
13
|
|
11
14
|
def contract(base = nil, &block)
|
12
15
|
if block_given?
|
@@ -24,7 +27,7 @@ module Pathway
|
|
24
27
|
end
|
25
28
|
|
26
29
|
def contract_class= klass
|
27
|
-
@contract_class
|
30
|
+
@contract_class = klass
|
28
31
|
@contract_options = (klass.dry_initializer.options - Dry::Validation::Contract.dry_initializer.options).map(&:target)
|
29
32
|
@builded_contract = @contract_options.empty? && klass.schema ? klass.new : nil
|
30
33
|
end
|
@@ -35,8 +38,8 @@ module Pathway
|
|
35
38
|
|
36
39
|
def inherited(subclass)
|
37
40
|
super
|
41
|
+
subclass.auto_wire = auto_wire
|
38
42
|
subclass.contract_class = contract_class
|
39
|
-
subclass.auto_wire_options = auto_wire_options
|
40
43
|
end
|
41
44
|
|
42
45
|
private
|
@@ -49,11 +52,11 @@ module Pathway
|
|
49
52
|
module InstanceMethods
|
50
53
|
extend Forwardable
|
51
54
|
|
52
|
-
delegate %i[build_contract contract_options auto_wire_options] => 'self.class'
|
53
|
-
|
55
|
+
delegate %i[build_contract contract_options auto_wire_options auto_wire] => 'self.class'
|
56
|
+
alias_method :contract, :build_contract
|
54
57
|
|
55
58
|
def validate(state, with: nil)
|
56
|
-
if
|
59
|
+
if auto_wire && contract_options.any?
|
57
60
|
with ||= contract_options.zip(contract_options).to_h
|
58
61
|
end
|
59
62
|
opts = Hash(with).map { |to, from| [to, state[from]] }.to_h
|
@@ -68,9 +71,15 @@ module Pathway
|
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
|
-
def self.apply(operation, auto_wire_options: false)
|
74
|
+
def self.apply(operation, auto_wire_options: (auto_wire_options_was_not_used=true; false), auto_wire: auto_wire_options)
|
75
|
+
#:nocov:
|
76
|
+
unless auto_wire_options_was_not_used
|
77
|
+
warn "[DEPRECATION] `auto_wire_options` is deprecated. Please use `auto_wire` instead"
|
78
|
+
end
|
79
|
+
#:nocov:
|
80
|
+
|
81
|
+
operation.auto_wire = auto_wire
|
72
82
|
operation.contract_class = Dry::Validation::Contract
|
73
|
-
operation.auto_wire_options = auto_wire_options
|
74
83
|
end
|
75
84
|
end
|
76
85
|
end
|
data/lib/pathway/version.rb
CHANGED
data/lib/pathway.rb
CHANGED
@@ -83,7 +83,27 @@ module Pathway
|
|
83
83
|
@hash
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
def use(&bl)
|
87
|
+
raise ArgumentError, 'a block must be provided' if !block_given?
|
88
|
+
if bl.parameters.any? {|(type,_)| type == :keyrest || type == :rest }
|
89
|
+
raise ArgumentError, 'rest arguments are not supported'
|
90
|
+
end
|
91
|
+
|
92
|
+
keys = bl.parameters.select {|(type,_)| type == :key || type == :keyreq }.map(&:last)
|
93
|
+
names = bl.parameters.select {|(type,_)| type == :req || type == :opt }.map(&:last)
|
94
|
+
|
95
|
+
if keys.any? && names.any?
|
96
|
+
raise ArgumentError, 'cannot mix positional and keyword arguments'
|
97
|
+
elsif keys.any?
|
98
|
+
bl.call(**to_hash.slice(*keys))
|
99
|
+
else
|
100
|
+
bl.call(*to_hash.values_at(*names))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
alias_method :to_h, :to_hash
|
105
|
+
alias_method :u, :use
|
106
|
+
alias_method :unwrap, :use
|
87
107
|
end
|
88
108
|
|
89
109
|
module Plugins
|
data/pathway.gemspec
CHANGED
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.12.
|
4
|
+
version: 0.12.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Herrero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-inflector
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: pry-stack
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
195
209
|
description: Define your business logic in simple steps.
|
196
210
|
email:
|
197
211
|
- pablodherrero@gmail.com
|