pathway 0.12.2 → 0.12.3

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: 29e0024427e53290982fedc6eadaacbbf3555627e94930d1c52d3bdcbb90a5dd
4
- data.tar.gz: 98fbe3a72e2aa4c1a3a6b0c1a9ed610231256364b4db44e7840da261bac5a47f
3
+ metadata.gz: 83205585dcf796cdb4a5da8055163491d12586c48915e6d3ef7efe44ff6533f3
4
+ data.tar.gz: 1584cfc7dd38e44e14a810a96a658e29b5756aad62f36e1e69671a3c7631a656
5
5
  SHA512:
6
- metadata.gz: 81ee05e3aec188a87df7b59032099cfcfb7c59e4641ab6b0db8ebe02bcf693d53fec4db3de16bb62d96e8e84cdf6f45e995411429c53818c748b320da7aa06a2
7
- data.tar.gz: f64c5e2d2bc08afcca58b62a53dbb98511f59d6f7588e59732c434f0abaae103ac00c2153e76f6b2b2eeb034855bdf1c2561cfa44ce15885ab12be5fa815f1b3
6
+ metadata.gz: ade86174156600eb76a84af9ca96097eaa28a8760ba52f150fc9ed6c21ca5a69e387157cb7238c97990aa516ff712b98708941acf4885805e9bb4f8d85db2757
7
+ data.tar.gz: 855252fa3e0639a3d18bd1f0f10f7d379795516723da702c6201076a3767dc3a7f447191260d137f57716bf57915e654270a0209b6b3e36de9896e54faac7927
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
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
+
1
9
  ## [0.12.2] - 2024-08-06
2
10
  ### Added
3
11
  - Add `Pathway::State#unwrap` and `Pathway::State#u` to access internal state
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 `auto_wire_options: true` plugin argument or specify how to map options from the execution state to the contract when calling `step :validate`.
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, auto_wire_options: true
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 `:auto_wire_options`, afterwards, when the validation runs, the contract will already have the user name available.
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
 
@@ -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 :auto_wire_options
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.auto_wire_options = auto_wire_options
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
- alias :form :build_form
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 auto_wire_options && form_options.any?
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 :auto_wire_options
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.auto_wire_options = auto_wire_options
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
- alias :form :build_form
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 auto_wire_options && form_options.any?
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 :auto_wire_options
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 = klass
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
- alias :contract :build_contract
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 auto_wire_options && contract_options.any?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pathway
4
- VERSION = '0.12.2'
4
+ VERSION = '0.12.3'
5
5
  end
data/lib/pathway.rb CHANGED
@@ -83,23 +83,27 @@ module Pathway
83
83
  @hash
84
84
  end
85
85
 
86
- def unwrap(&bl)
87
- raise 'a block must be provided' if !block_given?
88
- params = bl.parameters
89
- unless params.all? { |(type,_)| [:block, :key, :keyreq, :keyrest].member?(type) }
90
- raise 'only keyword arguments are supported for unwraping'
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'
91
90
  end
92
91
 
93
- if params.any? {|(type,_)| type == :keyrest }
94
- bl.call(**to_hash)
95
- else
96
- keys = params.select {|(type,_)| type == :key || type == :keyreq }.map(&:last)
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?
97
98
  bl.call(**to_hash.slice(*keys))
99
+ else
100
+ bl.call(*to_hash.values_at(*names))
98
101
  end
99
102
  end
100
103
 
101
104
  alias_method :to_h, :to_hash
102
- alias_method :u, :unwrap
105
+ alias_method :u, :use
106
+ alias_method :unwrap, :use
103
107
  end
104
108
 
105
109
  module Plugins
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.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Herrero
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-06 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -254,7 +254,7 @@ licenses:
254
254
  metadata:
255
255
  bug_tracker_uri: https://github.com/pabloh/pathway/issues
256
256
  source_code_uri: https://github.com/pabloh/pathway
257
- post_install_message:
257
+ post_install_message:
258
258
  rdoc_options: []
259
259
  require_paths:
260
260
  - lib
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  version: '0'
271
271
  requirements: []
272
272
  rubygems_version: 3.5.10
273
- signing_key:
273
+ signing_key:
274
274
  specification_version: 4
275
275
  summary: Define your business logic in simple steps.
276
276
  test_files: []