dryer_routes 0.4.0 → 0.5.1

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: db3c5e4d0a5b6da6c17cd4c52744a5ef90382e6de723d17a3b8661408033c4df
4
+ data.tar.gz: 409d7ba0396eea7e623d719861cd030438fa7dde30fbe7b71c72536acb962d6b
5
5
  SHA512:
6
- metadata.gz: 8665e3876446c5dc83971571917abfdc6aab99ebba6966d4a4a9e926121bdf30ce36118c653602250b1be30fe3dece2af7eb35219e6fea9e966e4284ee63211d
7
- data.tar.gz: 28f31b3bbd90f85cef8d04e843607544bd234c512817d07a5ccfe2a501f23db66a9394aaa51be489d36de8c947348656d6462d95b812aa7c5252878b481bc0f4
6
+ metadata.gz: 062e66fb4a47a501e52bc88764c774ff8a2715b5fe0445bf33c3ca11436ada9846c79cc734f984f219b668845a41087b48614b04004d0fec82db8fc0b73e6861
7
+ data.tar.gz: cecbf962ae3c78329a2a0aa2bc8da858cc15942ca1f07b60d1178bb32c86226b2aa69a6ed15b13c4d90617b83f441a00b37287227e6ace70770227224d5c57af
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.1"
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'
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "dry-validation", "~> 1.10"
26
26
  spec.add_dependency "dry-types", "~> 1.7"
27
27
  spec.add_dependency "dryer_services", "~> 2.0"
28
+ spec.add_dependency "zeitwerk", "~> 2.6"
28
29
  spec.add_development_dependency "rspec", "~> 3.10"
29
30
  spec.add_development_dependency "debug", "~> 1.8"
30
31
  end
@@ -1,4 +1,3 @@
1
- require_relative "./route"
2
1
  require "dryer_services"
3
2
 
4
3
  module Dryer
@@ -12,7 +11,9 @@ module Dryer
12
11
  resource[:actions].map do |action, config|
13
12
  Route.new(
14
13
  controller: resource[:controller],
15
- url: config[:url] || resource[:url],
14
+ url: Dryer::Routes::UrlBuilder.call(
15
+ config[:url] || resource[:url]
16
+ ),
16
17
  method: config[:method],
17
18
  controller_action: action,
18
19
  request_contract: config[:request_contract],
@@ -1,8 +1,3 @@
1
- require_relative "./build_from_resource.rb"
2
- require_relative "./hash_object.rb"
3
- require_relative "./resource_schema.rb"
4
- require_relative "./extract_validated_keys.rb"
5
-
6
1
  module Dryer
7
2
  module Routes
8
3
  class Registry
@@ -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,42 @@
1
+ require "dryer_services"
2
+
3
+ module Dryer
4
+ module Routes
5
+ class UrlBuilder < Dryer::Services::SimpleService
6
+ def initialize(url)
7
+ @url = url
8
+ end
9
+
10
+ def call
11
+ if contains_path_variables?
12
+ url_function
13
+ else
14
+ url
15
+ end
16
+ end
17
+
18
+ private
19
+ attr_reader :url
20
+
21
+ def path_variables
22
+ @path_variables ||= url.match(/(:\w*)/)
23
+ end
24
+
25
+ def contains_path_variables?
26
+ path_variables ? path_variables.length > 0 : false
27
+ end
28
+
29
+ def url_function
30
+ -> (*args) do
31
+ path_variables.to_a.zip(args).inject(url) do |path, (key, value)|
32
+ if key && value
33
+ path.sub(key.to_s, value.to_s)
34
+ else
35
+ path
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ require "zeitwerk"
2
+ require "rubygems"
3
+
4
+ module Dryer
5
+ module Routes
6
+ VERSION = Gem::Specification::load(
7
+ "./dryer_routes.gemspec"
8
+ ).version
9
+
10
+ def self.loader
11
+ @loader ||= Zeitwerk::Loader.new.tap do |loader|
12
+ root = File.expand_path("..", __dir__)
13
+ loader.tag = "dryer_routes"
14
+ loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry_routes.rb")
15
+ loader.push_dir(root)
16
+ loader.ignore(
17
+ "#{root}/dry_routes.rb",
18
+ )
19
+ end
20
+ end
21
+ loader.setup
22
+ end
23
+ end
data/lib/dryer_routes.rb CHANGED
@@ -1 +1 @@
1
- require_relative "./dryer/routes/registry.rb"
1
+ require_relative "./dryer/routes.rb"
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bernier
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: zeitwerk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.6'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.6'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +106,14 @@ files:
92
106
  - LICENSE
93
107
  - README.md
94
108
  - dryer_routes.gemspec
109
+ - lib/dryer/routes.rb
95
110
  - lib/dryer/routes/build_from_resource.rb
96
111
  - lib/dryer/routes/extract_validated_keys.rb
97
112
  - lib/dryer/routes/hash_object.rb
98
- - lib/dryer/routes/registries/create.rb
99
113
  - lib/dryer/routes/registry.rb
100
114
  - lib/dryer/routes/resource_schema.rb
101
115
  - lib/dryer/routes/route.rb
102
- - lib/dryer/routes/version.rb
116
+ - lib/dryer/routes/url_builder.rb
103
117
  - lib/dryer_routes.rb
104
118
  homepage: https://github.com/jbernie2/dryer-routes
105
119
  licenses:
@@ -1,11 +0,0 @@
1
- module Dryer
2
- module Routes
3
- module Registries
4
- class Create < SimpleService
5
- def call
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- require "rubygems"
2
-
3
- module Dryer
4
- module Routes
5
- VERSION = Gem::Specification::load(
6
- "./dryer_routes.gemspec"
7
- ).version
8
- end
9
- end