valid_route 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/valid_route/route_formatter.rb +31 -4
- data/lib/valid_route/route_validator.rb +2 -1
- data/lib/valid_route/version.rb +1 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/seeds.rb +16 -3
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +879 -0
- data/test/dummy/log/test.log +3168 -0
- data/test/dummy/test/valid_route/route_formatter_test.rb +26 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1130cb6b268faab104c6f5f98cbb3f627c8c9efb
|
4
|
+
data.tar.gz: 176d8334566adbcf622b4f8fc155194b963e338e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b58aba0c6901d37f5470ebb5605d3fd1ade2cdccffd1a2a32ee51f35d63dfe34b4b280898d86625ec0446403ac15a3cd561441fb57a718c959e1a4f40beda12e
|
7
|
+
data.tar.gz: a2383ab34be4985ba2f5272f2553493c9b39ee4ada97b94d3d37d605b9b6cc4f92d11e6e03f32035b67ec08e38998ae6556bcf9232108bcd2052ea3930de7e8a
|
@@ -2,17 +2,30 @@ module ValidRoute
|
|
2
2
|
class RouteFormatter
|
3
3
|
def initialize
|
4
4
|
@buffer = []
|
5
|
+
@current_route_set = nil
|
6
|
+
@main_app_routes = []
|
7
|
+
@engine_routes = []
|
5
8
|
end
|
6
9
|
|
7
10
|
def result
|
8
11
|
@buffer #.compact.uniq
|
9
12
|
end
|
10
13
|
|
11
|
-
def section_title(title)
|
14
|
+
def section_title(title) # only called for engines
|
15
|
+
engine_regexp = /Routes for (.*)/
|
16
|
+
if title.match(engine_regexp)
|
17
|
+
@current_route_set = title.slice(engine_regexp,1)
|
18
|
+
end
|
12
19
|
end
|
13
20
|
|
14
21
|
def section(routes)
|
15
|
-
|
22
|
+
formatted_routes = array_paths(routes)
|
23
|
+
if @main_app_routes.empty?
|
24
|
+
@main_app_routes = formatted_routes
|
25
|
+
else
|
26
|
+
@engine_routes << formatted_routes
|
27
|
+
end
|
28
|
+
@buffer << formatted_routes
|
16
29
|
@buffer.flatten!
|
17
30
|
end
|
18
31
|
|
@@ -25,10 +38,24 @@ module ValidRoute
|
|
25
38
|
|
26
39
|
private
|
27
40
|
def array_paths(routes)
|
28
|
-
|
41
|
+
format_regexp = "(.:format)"
|
42
|
+
path_prefix = ""
|
43
|
+
unless @current_route_set.nil?
|
44
|
+
engine_route = @main_app_routes.select { |r| r[:reqs] == @current_route_set}
|
45
|
+
unless engine_route.empty?
|
46
|
+
path_prefix = engine_route.first[:path]
|
47
|
+
@buffer = @buffer - engine_route
|
48
|
+
# @main_app_routes = @main_app_routes - engine_route
|
49
|
+
end
|
50
|
+
@current_route_set = nil
|
51
|
+
end
|
29
52
|
paths = []
|
30
53
|
routes.map do |r|
|
31
|
-
|
54
|
+
path = r[:path].sub(format_regexp, "")
|
55
|
+
path = path_prefix + path
|
56
|
+
path = path[1..-1] if path[0..1] == "//"
|
57
|
+
path.chop! if path[-1, 1] == "/" and path != "/"
|
58
|
+
paths << {path: path, verb: r[:verb], reqs: r[:reqs], name: r[:name] }
|
32
59
|
end
|
33
60
|
paths
|
34
61
|
end
|
@@ -43,7 +43,7 @@ class RouteValidator < ActiveModel::EachValidator
|
|
43
43
|
unless route == route_to_create
|
44
44
|
parameter = route_to_create[:path].split(/.*?(:[^\/]*)/).last || ""
|
45
45
|
substituted_route = route_to_create[:path].sub(parameter, record.to_param)
|
46
|
-
if (route[:path] == route_to_create[:path]) or (route[:path] == substituted_route)
|
46
|
+
if (route[:path] == route_to_create[:path]) or (route[:path] == substituted_route) and route[:reqs] != route_to_create[:reqs]
|
47
47
|
possible_conflicts.push route
|
48
48
|
end
|
49
49
|
end
|
@@ -71,6 +71,7 @@ class RouteValidator < ActiveModel::EachValidator
|
|
71
71
|
routes_to_create.each {|route_to_create|
|
72
72
|
if route[:reqs].include?("#show") or route[:reqs].include?("#edit")
|
73
73
|
if route[:reqs].include?("/") # is this a namespaced route or anything?
|
74
|
+
puts route[:reqs]
|
74
75
|
route_controller_segments = route[:reqs].slice(/(.*)(#)(.*)/, 1).split(/^(.*\/)(.*)$/)
|
75
76
|
last_segment = route_controller_segments.pop.singularize
|
76
77
|
klass_underscored = route_controller_segments.join("") + last_segment
|
data/lib/valid_route/version.rb
CHANGED
Binary file
|
data/test/dummy/db/seeds.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
unless Page.exists?('home')
|
2
|
+
Page.create(
|
3
|
+
{:name => 'Home', :permalink => 'home', :content => 'Home Page'},
|
4
|
+
)
|
5
|
+
end
|
3
6
|
|
4
|
-
|
7
|
+
unless Page.exists?('contact')
|
8
|
+
Page.create(
|
9
|
+
{:name => 'Contact', :permalink => 'contact', :content => 'Contact Page'}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
unless User.exists?('admin')
|
14
|
+
User.create(
|
15
|
+
{:username => 'admin', :first_name => 'Admin', :password => 'password'}
|
16
|
+
)
|
17
|
+
end
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|