dryer_routes 0.4.0 → 0.5.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: b6a00c3b22caa974de5bec04599dc6b40a32523eaaa484d6d571834d778646ca
4
- data.tar.gz: 7cdb3a01b272969893c262d41766e1a5da1267f80862d21e0f96644811fe9a0d
3
+ metadata.gz: 1111d6f7ed55f154190ba49699ebc7cbb8dc1d960709557907b2577ddca7f6b4
4
+ data.tar.gz: 0deee81d1747cfc58c5810ca52841e6138c3b0fe0346b924436cb7882a9d5b7a
5
5
  SHA512:
6
- metadata.gz: 8665e3876446c5dc83971571917abfdc6aab99ebba6966d4a4a9e926121bdf30ce36118c653602250b1be30fe3dece2af7eb35219e6fea9e966e4284ee63211d
7
- data.tar.gz: 28f31b3bbd90f85cef8d04e843607544bd234c512817d07a5ccfe2a501f23db66a9394aaa51be489d36de8c947348656d6462d95b812aa7c5252878b481bc0f4
6
+ metadata.gz: c7b1a039f2781bc101392ca06b5722cd5bd545bd585c8459a7e6328a67c02eefec0f79d833fdc85a3b105ccfb29e58355d50a9f6ccca600be82771682d117bee
7
+ data.tar.gz: 3eacb0a2685e42e4a96d6ce7cfb26714bb640713b5c1cd3aff146e21f1ff918c65ed75717342f9cb92ea6984c58f4ac59355ef696f6e3e1631023eada3bc2cb7
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.4.0"
3
+ spec.version = "0.5.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'
@@ -12,7 +12,9 @@ module Dryer
12
12
  resource[:actions].map do |action, config|
13
13
  Route.new(
14
14
  controller: resource[:controller],
15
- url: config[:url] || resource[:url],
15
+ url: Dryer::Routes::UrlBuilder.call(
16
+ config[:url] || resource[:url]
17
+ ),
16
18
  method: config[:method],
17
19
  controller_action: action,
18
20
  request_contract: config[:request_contract],
@@ -33,8 +33,12 @@ module Dryer
33
33
  route_config[:response_contracts][status]
34
34
  end
35
35
 
36
- def url
37
- route_config[:url]
36
+ def url(*args)
37
+ if route_config[:url].is_a?(Proc)
38
+ route_config[:url].call(*args)
39
+ else
40
+ route_config[:url]
41
+ end
38
42
  end
39
43
 
40
44
  private
@@ -0,0 +1,43 @@
1
+ require "dryer_services"
2
+ require "debug"
3
+
4
+ module Dryer
5
+ module Routes
6
+ class UrlBuilder < Dryer::Services::SimpleService
7
+ def initialize(url)
8
+ @url = url
9
+ end
10
+
11
+ def call
12
+ if contains_path_variables?
13
+ url_function
14
+ else
15
+ url
16
+ end
17
+ end
18
+
19
+ private
20
+ attr_reader :url
21
+
22
+ def path_variables
23
+ @path_variables ||= url.match(/(:\w*)/)
24
+ end
25
+
26
+ def contains_path_variables?
27
+ path_variables ? path_variables.length > 0 : false
28
+ end
29
+
30
+ def url_function
31
+ -> (*args) do
32
+ path_variables.to_a.zip(args).inject(url) do |path, (key, value)|
33
+ if key && value
34
+ path.sub(key.to_s, value.to_s)
35
+ else
36
+ path
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ 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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bernier
@@ -99,6 +99,7 @@ files:
99
99
  - lib/dryer/routes/registry.rb
100
100
  - lib/dryer/routes/resource_schema.rb
101
101
  - lib/dryer/routes/route.rb
102
+ - lib/dryer/routes/url_builder.rb
102
103
  - lib/dryer/routes/version.rb
103
104
  - lib/dryer_routes.rb
104
105
  homepage: https://github.com/jbernie2/dryer-routes