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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd3f318f6e79d420b9f41465980ea0f334f98d86
4
- data.tar.gz: 70923f6e407e55a9d0f96eb0e2f8770c6f5ee490
3
+ metadata.gz: 1130cb6b268faab104c6f5f98cbb3f627c8c9efb
4
+ data.tar.gz: 176d8334566adbcf622b4f8fc155194b963e338e
5
5
  SHA512:
6
- metadata.gz: a2c74f43755922cd08238e68e4edeeef7cc1b55a09abada9dfbfaf6f9bda3a667dbdc1a21945b292cfff3bae9b9af4e3c9d452ec6d763f0942e7f1c8f3908045
7
- data.tar.gz: 8cab5c0c3f9d91a8de8090564af351f9c110776c4b2cf6a7328b7acaac267de35cfb6b3f47e27c22a43d952562c632a6d4c9c0b195fa1f091c077268db9cdd53
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
- @buffer << array_paths(routes)
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
- regexp = "(.:format)"
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
- paths << {path: r[:path].sub(regexp, ""), verb: r[:verb], reqs: r[:reqs] }
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
@@ -1,3 +1,3 @@
1
1
  module ValidRoute
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
@@ -1,4 +1,17 @@
1
- FactoryGirl.create(:home_page)
2
- FactoryGirl.create(:contact_page)
1
+ unless Page.exists?('home')
2
+ Page.create(
3
+ {:name => 'Home', :permalink => 'home', :content => 'Home Page'},
4
+ )
5
+ end
3
6
 
4
- FactoryGirl.create(:user, username: "vjm", first_name: "Vince", password: "weekend")
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
Binary file