pathway 0.12.3 → 1.1.0
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/.github/workflows/tests.yml +2 -2
- data/CHANGELOG.md +14 -0
- data/README.md +0 -4
- data/bin/bundle +109 -0
- data/bin/byebug +13 -3
- data/bin/coderay +27 -0
- data/bin/erb +27 -0
- data/bin/htmldiff +27 -0
- data/bin/irb +27 -0
- data/bin/ldiff +27 -0
- data/bin/pry +27 -0
- data/bin/rake +13 -3
- data/bin/rbs +27 -0
- data/bin/rdbg +27 -0
- data/bin/rdoc +27 -0
- data/bin/ri +27 -0
- data/bin/rspec +13 -3
- data/bin/ruby-lsp +27 -0
- data/bin/ruby-lsp-check +27 -0
- data/bin/ruby-lsp-launcher +27 -0
- data/bin/ruby-lsp-test-exec +27 -0
- data/bin/sequel +27 -0
- data/bin/yard +27 -0
- data/bin/yardoc +27 -0
- data/bin/yri +27 -0
- data/lib/pathway/plugins/auto_deconstruct_state.rb +14 -4
- data/lib/pathway/plugins/dry_validation.rb +73 -12
- data/lib/pathway/plugins/responder.rb +5 -7
- data/lib/pathway/plugins/sequel_models.rb +35 -25
- data/lib/pathway/plugins/simple_auth.rb +1 -3
- data/lib/pathway/result.rb +18 -44
- data/lib/pathway/rspec/matchers/fail_on.rb +6 -6
- data/lib/pathway/version.rb +1 -1
- data/lib/pathway.rb +42 -59
- data/pathway.gemspec +5 -4
- metadata +55 -29
- data/lib/pathway/plugins/auto_deconstruct_state/ruby3.rb +0 -22
- data/lib/pathway/plugins/dry_validation/v0_11.rb +0 -96
- data/lib/pathway/plugins/dry_validation/v0_12.rb +0 -95
- data/lib/pathway/plugins/dry_validation/v1_0.rb +0 -87
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Pathway
|
4
|
-
module Plugins
|
5
|
-
module DryValidation
|
6
|
-
module V1_0
|
7
|
-
module ClassMethods
|
8
|
-
attr_reader :contract_class, :contract_options
|
9
|
-
attr_accessor :auto_wire
|
10
|
-
|
11
|
-
alias_method :auto_wire_options, :auto_wire
|
12
|
-
alias_method :auto_wire_options=, :auto_wire=
|
13
|
-
|
14
|
-
def contract(base = nil, &block)
|
15
|
-
if block_given?
|
16
|
-
base ||= _base_contract
|
17
|
-
self.contract_class = Class.new(base, &block)
|
18
|
-
elsif base
|
19
|
-
self.contract_class = base
|
20
|
-
else
|
21
|
-
raise ArgumentError, 'Either a contract class or a block must be provided'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
ruby2_keywords def params(*args, &block)
|
26
|
-
contract { params(*args, &block) }
|
27
|
-
end
|
28
|
-
|
29
|
-
def contract_class= klass
|
30
|
-
@contract_class = klass
|
31
|
-
@contract_options = (klass.dry_initializer.options - Dry::Validation::Contract.dry_initializer.options).map(&:target)
|
32
|
-
@builded_contract = @contract_options.empty? && klass.schema ? klass.new : nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def build_contract(**opts)
|
36
|
-
@builded_contract || contract_class.new(**opts)
|
37
|
-
end
|
38
|
-
|
39
|
-
def inherited(subclass)
|
40
|
-
super
|
41
|
-
subclass.auto_wire = auto_wire
|
42
|
-
subclass.contract_class = contract_class
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def _base_contract
|
48
|
-
superclass.respond_to?(:contract_class) ? superclass.contract_class : Dry::Validation::Contract
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module InstanceMethods
|
53
|
-
extend Forwardable
|
54
|
-
|
55
|
-
delegate %i[build_contract contract_options auto_wire_options auto_wire] => 'self.class'
|
56
|
-
alias_method :contract, :build_contract
|
57
|
-
|
58
|
-
def validate(state, with: nil)
|
59
|
-
if auto_wire && contract_options.any?
|
60
|
-
with ||= contract_options.zip(contract_options).to_h
|
61
|
-
end
|
62
|
-
opts = Hash(with).map { |to, from| [to, state[from]] }.to_h
|
63
|
-
validate_with(state[:input], **opts)
|
64
|
-
.then { |params| state.update(params: params) }
|
65
|
-
end
|
66
|
-
|
67
|
-
def validate_with(input, **opts)
|
68
|
-
result = contract(**opts).call(input)
|
69
|
-
|
70
|
-
result.success? ? wrap(result.values.to_h) : error(:validation, details: result.errors.to_h)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
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
|
82
|
-
operation.contract_class = Dry::Validation::Contract
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|