rack-rewrite-dynamic 0.0.2 → 0.0.3
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.
@@ -19,6 +19,10 @@ module Rack
|
|
19
19
|
slug = find_sluggable(slug_name)
|
20
20
|
slug if slug && slug[:sluggable_type] == slug_type
|
21
21
|
end
|
22
|
+
def scoped_slug_type?(slug_name, slug_type, prev_slug)
|
23
|
+
association_name = slug_type.downcase.pluralize
|
24
|
+
prev_slug.sluggable.send(association_name).find(slug_name) if prev_slug
|
25
|
+
end
|
22
26
|
def find_sluggable(friendly_id)
|
23
27
|
slug_klass.find(friendly_id)
|
24
28
|
rescue ActiveRecord::RecordNotFound
|
@@ -3,7 +3,11 @@ module Rack
|
|
3
3
|
module Dynamic
|
4
4
|
class RailsRouteGenerator
|
5
5
|
def self.route_for slug
|
6
|
-
|
6
|
+
if slug.kind_of?(Slug)
|
7
|
+
Rails.application.routes.url_helpers.send("#{slug[:sluggable_type].underscore}_path", slug[:sluggable_id])
|
8
|
+
else
|
9
|
+
Rails.application.routes.url_helpers.send("#{slug.class.name.underscore}_path", slug.id)
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
@@ -25,9 +25,12 @@ module Rack
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def find_url(url_parts, match, rack_env)
|
28
|
+
scope_slug = nil
|
28
29
|
slugs = url_parts.each_with_index.map do |url_part, index|
|
29
30
|
if url_part[1] == 'slug'
|
30
|
-
slug_type?(match[index+1], url_part[0])
|
31
|
+
scope_slug = slug_type?(match[index+1], url_part[0])
|
32
|
+
elsif url_part[1] == 'scoped_slug'
|
33
|
+
scope_slug = scoped_slug_type?(match[index+1], url_part[0], scope_slug)
|
31
34
|
else
|
32
35
|
'static'
|
33
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-rewrite-dynamic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack-rewrite
|