dynamic_router 0.0.9 → 0.0.10

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
  SHA1:
3
- metadata.gz: a6f602701fcab286e0c5e053bcd6a82d54ebaa7e
4
- data.tar.gz: 17cd846d4ba3d9e787fd0eb8d7f996e8726811d4
3
+ metadata.gz: 543ab20c6bee3d7923fe190569a070b6a8f379d2
4
+ data.tar.gz: 661d66a572b0e9898e38249fceba62272e69a6e9
5
5
  SHA512:
6
- metadata.gz: 78fb249b744d7ba4abccf31f209a99fecdcd38f5f38fa29504fe44d71659a29e9cd483df4306d5c7f74f8ad039f151e06ad33562d5210aedfa71d7d95c687507
7
- data.tar.gz: 273e48fca1662ea204383cfc3036fdeefabe653ab6f1665f326a0a5fe3e2a45bfc6d7e982e0c57d09535cf689bfe82a87b431bc3ee47dbf2db4e44edcda66ebc
6
+ metadata.gz: 377572337cef53d523111cab62d6cafecd352c3715cb0fc03b8f417836081a11a4d188b9808c207db2929379c538545e0043eb44886e580b673b808cfc24a020
7
+ data.tar.gz: a885e7ca61004c097227f3b36a96daa1521e6281ceeeaa0389247368a27ce9c35141d0d0bf875f4451303be5f5186fb13a5bbe065e90686e4a321ecdde43d4cd
data/README.md CHANGED
@@ -28,7 +28,7 @@ Suppose you want to create a friendly URL for a resource based on fields of an e
28
28
 
29
29
  To create a route to a resource using the field 'url' as URL, add the following line to your routes.rb:
30
30
 
31
- DynamicRouter.has_dynamic_route_for Example, Proc.new {|example| "/#{example.url}"}, "dummy#dummy_method"
31
+ DynamicRouter::Router.has_dynamic_route_for Example, Proc.new {|example| "/#{example.url}"}, "dummy#dummy_method"
32
32
 
33
33
  After this when you create models like:
34
34
 
@@ -39,11 +39,11 @@ The dynamic router will create the routes "/abc" and "/123" mapping to DummyCont
39
39
 
40
40
  You can pass the desired HTTP method also:
41
41
 
42
- DynamicRouter.has_dynamic_route_for Example, Proc.new {|example| "/#{example.url}"}, "dummy#dummy_method", :method => :post
42
+ DynamicRouter::Router.has_dynamic_route_for Example, Proc.new {|example| "/#{example.url}"}, "dummy#dummy_method", :method => :post
43
43
 
44
44
  And can specify default values to be passed, like:
45
45
 
46
- DynamicRouter.has_dynamic_route_for Example, Proc.new {|example| "/#{example.url}"}, "dummy#dummy_method", :defaults => {:some_value => Proc.new {|example| example.default_field}}
46
+ DynamicRouter::Router.has_dynamic_route_for Example, Proc.new {|example| "/#{example.url}"}, "dummy#dummy_method", :defaults => {:some_value => Proc.new {|example| example.default_field}}
47
47
 
48
48
  The dynamic router will map ALL records of the model on the startup and will create an after_save hook to create new routes as the models are created.
49
49
 
@@ -1,3 +1,3 @@
1
1
  module DynamicRouter
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require "dynamic_router/version"
2
2
 
3
3
  module DynamicRouter
4
- module_function
5
- def has_dynamic_route_for(klass, url, target, options = {})
4
+ class Router
5
+ def self.has_dynamic_route_for(klass, url, target, options = {})
6
6
  route_method = options[:method] || :get
7
7
 
8
8
  if ActiveRecord::Base.connection.table_exists? klass.table_name
@@ -35,4 +35,5 @@ module DynamicRouter
35
35
  end
36
36
  end
37
37
  end
38
+ end
38
39
  end
@@ -18,13 +18,13 @@ RSpec.describe DynamicRouter do
18
18
  expect(connection).to receive(:table_exists?).with(Example.table_name)
19
19
 
20
20
  Rails.application.routes.draw do
21
- DynamicRouter.has_dynamic_route_for(Example, Proc.new {|example| "/#{example.first_path}/#{example.second_path}"}, "dummy#dummy_method")
21
+ DynamicRouter::Router.has_dynamic_route_for(Example, Proc.new {|example| "/#{example.first_path}/#{example.second_path}"}, "dummy#dummy_method")
22
22
  end
23
23
  end
24
24
 
25
25
  it "should create a get route with the supplied url" do
26
26
  Rails.application.routes.draw do
27
- DynamicRouter.has_dynamic_route_for(Example, Proc.new {|example| "/#{example.first_path}/#{example.second_path}"}, "dummy#dummy_method")
27
+ DynamicRouter::Router.has_dynamic_route_for(Example, Proc.new {|example| "/#{example.first_path}/#{example.second_path}"}, "dummy#dummy_method")
28
28
  end
29
29
 
30
30
  expect(Rails.application.routes.recognize_path('/path_a/path_a_a', :method => :get))
@@ -33,7 +33,7 @@ RSpec.describe DynamicRouter do
33
33
 
34
34
  it "should accept the method option" do
35
35
  Rails.application.routes.draw do
36
- DynamicRouter.has_dynamic_route_for(Example, Proc.new {|example| "/#{example.first_path}/#{example.second_path}"}, "dummy#dummy_method", :method => :post)
36
+ DynamicRouter::Router.has_dynamic_route_for(Example, Proc.new {|example| "/#{example.first_path}/#{example.second_path}"}, "dummy#dummy_method", :method => :post)
37
37
  end
38
38
 
39
39
  expect(Rails.application.routes.recognize_path('/path_a/path_a_a', :method => :post))
@@ -41,7 +41,7 @@ RSpec.describe DynamicRouter do
41
41
 
42
42
  it "should accept the defaults option" do
43
43
  Rails.application.routes.draw do
44
- DynamicRouter.has_dynamic_route_for(Example, Proc.new {|example| "/#{example.first_path}/#{example.second_path}"}, "dummy#dummy_method", :defaults => {:default_value => Proc.new {|example| example.default_field}})
44
+ DynamicRouter::Router.has_dynamic_route_for(Example, Proc.new {|example| "/#{example.first_path}/#{example.second_path}"}, "dummy#dummy_method", :defaults => {:default_value => Proc.new {|example| example.default_field}})
45
45
  end
46
46
 
47
47
  expect(Rails.application.routes.routes.named_routes["path_a_path_a_a"].defaults).to match a_hash_including(:default_value => "default_value")
@@ -55,7 +55,7 @@ RSpec.describe DynamicRouter do
55
55
 
56
56
  it "should not create the route if the url is blank" do
57
57
  Rails.application.routes.draw do
58
- DynamicRouter.has_dynamic_route_for(Example, Proc.new {|example| ""}, "dummy#dummy_method")
58
+ DynamicRouter::Router.has_dynamic_route_for(Example, Proc.new {|example| ""}, "dummy#dummy_method")
59
59
  end
60
60
 
61
61
  expect(Rails.application.routes.routes.named_routes).to be_empty
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Berdugo