dryer_routes 0.5.3 → 0.6.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: 5c692380d53fff96240d6883e92c95894cd6eaf16ba0d18de34ae70eed293c0c
4
- data.tar.gz: 3ce4ca0aa75e253a70f994c86efca79491257bd4562deff01f1621c3eff78d0c
3
+ metadata.gz: 1e1bd1a21ffca48f41fc0006c91c7fb74d5ba63dccaa832243b974fdd83986fa
4
+ data.tar.gz: 92142801197d90929bdcfa7ac221512558f5a6a42dfbb98c1a422108def8c5b0
5
5
  SHA512:
6
- metadata.gz: 1fb38fc119af2c46a455ebe7e647060c02de3abff1604dd40ae2e63a324b44ee74180630d3d84f068866572db658b5cbfef4a30d6b28e7cd7648c63fb37523df
7
- data.tar.gz: cc9083eb11bd03929b09e40be4cc1d6c33f824c0ba3fc91cee0f30f9b23d70287a13a2b590519aa9863775d29bfd6c9736c7b36a5028ec4812a2ef0981806d6e
6
+ metadata.gz: d91227c0ff46538dbbc76c25d3e266b1d35ba37aa8c6245d04df5d9be8ccf55dd56eafb5041e88dbc488121a9bb834b5bea25a954517eea82874546460ab9aa4
7
+ data.tar.gz: 8aa179a4780e0fb5ac9540b24cb2fad708456fb7fb0079b296434ccd51de4e258886bc19a314686378290f57025e671c4ac38f8a7339a266eaf4cbdcc0d2e7b7
data/dryer_routes.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'dryer_routes'
3
- spec.version = "0.5.3"
3
+ spec.version = "0.6.0"
4
4
  spec.authors = ['John Bernier']
5
5
  spec.email = ['john.b.bernier@gmail.com']
6
6
  spec.summary = 'Typed routing for rails leveraging dry-validation contracts'
@@ -15,6 +15,7 @@ module Dryer
15
15
  method: config[:method],
16
16
  controller_action: action,
17
17
  request_contract: config[:request_contract],
18
+ url_parameters_contract: config[:url_parameters_contract],
18
19
  response_contracts: config[:response_contracts]
19
20
  )
20
21
  end
@@ -35,6 +35,19 @@ module Dryer
35
35
  end
36
36
  end
37
37
 
38
+ def validate_url_parameters(request)
39
+ route_for(
40
+ controller: request.controller_class,
41
+ method: request.request_method_symbol
42
+ ).then do |route|
43
+ if route && route.url_parameters_contract
44
+ route.url_parameters_contract.new.call(request.params).errors
45
+ else
46
+ []
47
+ end
48
+ end
49
+ end
50
+
38
51
  def validate_response(controller:, method:, status:, body:)
39
52
  route_for(
40
53
  controller: controller.class,
@@ -55,7 +68,7 @@ module Dryer
55
68
  end.first
56
69
  end
57
70
 
58
- def get_validated_values(request)
71
+ def validated_request_body(request)
59
72
  route_for(
60
73
  controller: request.controller_class,
61
74
  method: request.request_method_symbol
@@ -67,6 +80,18 @@ module Dryer
67
80
  end
68
81
  end
69
82
 
83
+ def validated_url_parameters(request)
84
+ route_for(
85
+ controller: request.controller_class,
86
+ method: request.request_method_symbol
87
+ ).then do |route|
88
+ ExtractValidatedKeys.call(
89
+ payload: request.params,
90
+ contract: route.url_parameters_contract
91
+ )
92
+ end
93
+ end
94
+
70
95
  attr_reader :routes, :resources
71
96
 
72
97
  private
@@ -13,18 +13,25 @@ module Dryer
13
13
  params do
14
14
  required(:method).filled(:symbol)
15
15
  optional(:request_contract)
16
+ optional(:url_parameters_contract)
16
17
  optional(:response_contracts).hash()
17
18
  end
18
19
 
19
20
  rule(:request_contract) do
20
- if value && !value.ancestors.include?(Dry::Validation::Contract)
21
+ if value && !(value <= Dry::Validation::Contract)
22
+ key.failure('must be a dry-validation contract')
23
+ end
24
+ end
25
+
26
+ rule(:url_parameters_contract) do
27
+ if value && !(value <= Dry::Validation::Contract)
21
28
  key.failure('must be a dry-validation contract')
22
29
  end
23
30
  end
24
31
 
25
32
  rule(:response_contracts) do
26
33
  values[:response_contracts].each do |key, value|
27
- if !value.ancestors.include?(Dry::Validation::Contract)
34
+ if !(value <= Dry::Validation::Contract)
28
35
  key(:response_contracts).failure(
29
36
  'must be a dry-validation contract'
30
37
  )
@@ -29,6 +29,10 @@ module Dryer
29
29
  route_config[:request_contract]
30
30
  end
31
31
 
32
+ def url_parameters_contract
33
+ route_config[:url_parameters_contract]
34
+ end
35
+
32
36
  def response_contract_for(status)
33
37
  route_config[:response_contracts][status]
34
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dryer_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bernier