rad_core 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/Rakefile +2 -2
  2. data/bin/rad +20 -25
  3. data/lib/components/config.rb +1 -1
  4. data/lib/components/configurators.rb +2 -2
  5. data/lib/components/controller.rb +2 -2
  6. data/lib/components/conveyors.rb +2 -2
  7. data/lib/components/environment.rb +1 -1
  8. data/lib/components/environment.yml +28 -28
  9. data/lib/components/flash.rb +1 -1
  10. data/lib/components/html.rb +1 -1
  11. data/lib/components/http.rb +1 -1
  12. data/lib/components/http.yml +1 -1
  13. data/lib/components/logger.rb +2 -2
  14. data/lib/components/mailer.rb +2 -2
  15. data/lib/components/remote.rb +1 -1
  16. data/lib/components/router.rb +3 -3
  17. data/lib/components/template.rb +2 -2
  18. data/lib/components/web.rb +3 -3
  19. data/lib/rad.rb +1 -1
  20. data/lib/rad/_support/active_support.rb +7 -7
  21. data/lib/rad/_support/active_support/locales/ru/actionview.yml +8 -8
  22. data/lib/rad/_support/active_support/locales/ru/activesupport.yml +4 -4
  23. data/lib/rad/_support/active_support/locales/ru/datetime.yml +5 -5
  24. data/lib/rad/_support/active_support/time.rb +2 -2
  25. data/lib/rad/_support/addressable.rb +6 -6
  26. data/lib/rad/_support/class_loader.rb +1 -1
  27. data/lib/rad/_support/extensions.rb +5 -5
  28. data/lib/rad/_support/filters.rb +13 -13
  29. data/lib/rad/_support/hacks_and_fixes.rb +5 -5
  30. data/lib/rad/_support/mime.rb +4 -4
  31. data/lib/rad/_support/module.rb +11 -11
  32. data/lib/rad/_support/require.rb +5 -5
  33. data/lib/rad/_support/rson.rb +4 -4
  34. data/lib/rad/_support/string.rb +9 -9
  35. data/lib/rad/cli/helper.rb +5 -5
  36. data/lib/rad/configurators/_require.rb +2 -2
  37. data/lib/rad/configurators/abstract.rb +5 -5
  38. data/lib/rad/configurators/web.rb +8 -8
  39. data/lib/rad/controller/_abstract.rb +15 -14
  40. data/lib/rad/controller/_abstract/miscellaneous.rb +5 -5
  41. data/lib/rad/controller/_abstract/render.rb +40 -40
  42. data/lib/rad/controller/_abstract/responder.rb +1 -1
  43. data/lib/rad/controller/_context.rb +1 -1
  44. data/lib/rad/controller/_http.rb +11 -11
  45. data/lib/rad/controller/_require.rb +6 -6
  46. data/lib/rad/controller/processors/controller_caller.rb +3 -3
  47. data/lib/rad/controller/processors/controller_error_handling.rb +14 -14
  48. data/lib/rad/controller/processors/controller_logger.rb +1 -1
  49. data/lib/rad/conveyors/_conveyor.rb +9 -9
  50. data/lib/rad/conveyors/_conveyors.rb +4 -4
  51. data/lib/rad/conveyors/_params.rb +5 -5
  52. data/lib/rad/conveyors/_processor.rb +2 -2
  53. data/lib/rad/conveyors/_workspace.rb +5 -5
  54. data/lib/rad/conveyors/processors/conveyor_logger.rb +3 -3
  55. data/lib/rad/environment/_config.rb +4 -4
  56. data/lib/rad/environment/_environment.rb +10 -10
  57. data/lib/rad/environment/_files_helper.rb +5 -5
  58. data/lib/rad/environment/_logger.rb +9 -9
  59. data/lib/rad/environment/_require.rb +4 -4
  60. data/lib/rad/gems.rb +14 -14
  61. data/lib/rad/html/_flash.rb +5 -5
  62. data/lib/rad/html/_helpers/basic_html_helper.rb +12 -12
  63. data/lib/rad/html/_helpers/form_helper.rb +19 -19
  64. data/lib/rad/html/_helpers/javascript_helper.rb +6 -6
  65. data/lib/rad/html/_helpers/model_helper.rb +17 -17
  66. data/lib/rad/html/_require.rb +1 -1
  67. data/lib/rad/html/processors/prepare_flash.rb +3 -3
  68. data/lib/rad/html/processors/scoped_params.rb +4 -4
  69. data/lib/rad/http/_http.rb +4 -4
  70. data/lib/rad/http/_http_adapter.rb +5 -5
  71. data/lib/rad/http/_request.rb +11 -11
  72. data/lib/rad/http/_require.rb +8 -8
  73. data/lib/rad/http/_response.rb +5 -5
  74. data/lib/rad/http/_support/rack/fixes.rb +3 -3
  75. data/lib/rad/http/_support/rack/rack_adapter.rb +5 -5
  76. data/lib/rad/http/processors/evaluate_format.rb +4 -4
  77. data/lib/rad/http/processors/http_logger.rb +3 -3
  78. data/lib/rad/http/processors/http_writer.rb +7 -7
  79. data/lib/rad/http/processors/prepare_params.rb +5 -5
  80. data/lib/rad/mailer/_letter.rb +1 -1
  81. data/lib/rad/mailer/_mailer.rb +1 -1
  82. data/lib/rad/mailer/_mailer_controller.rb +6 -6
  83. data/lib/rad/mailer/_require.rb +1 -1
  84. data/lib/rad/mailer/processors/letter_builder.rb +6 -6
  85. data/lib/rad/profiles/mailer.rb +2 -2
  86. data/lib/rad/profiles/web.rb +13 -13
  87. data/lib/rad/remote/processors/remote_caller.rb +10 -10
  88. data/lib/rad/remote/processors/remote_logger.rb +1 -1
  89. data/lib/rad/router/_abstract_router.rb +9 -9
  90. data/lib/rad/router/_alias_router.rb +34 -34
  91. data/lib/rad/router/_basic_router.rb +12 -12
  92. data/lib/rad/router/_configurator.rb +6 -6
  93. data/lib/rad/router/_core_routing_helper.rb +4 -4
  94. data/lib/rad/router/_object_router.rb +45 -45
  95. data/lib/rad/router/_require.rb +8 -8
  96. data/lib/rad/router/_restful_router.rb +25 -25
  97. data/lib/rad/router/_router.rb +78 -78
  98. data/lib/rad/router/_simple_router.rb +5 -5
  99. data/lib/rad/router/processors/router.rb +6 -6
  100. data/lib/rad/spec/controller.rb +9 -9
  101. data/lib/rad/spec/environment.rb +7 -7
  102. data/lib/rad/spec/http.rb +2 -2
  103. data/lib/rad/spec/http_controller.rb +22 -22
  104. data/lib/rad/spec/mailer.rb +4 -4
  105. data/lib/rad/spec/remote.rb +1 -1
  106. data/lib/rad/spec/router.rb +4 -4
  107. data/lib/rad/spec/template.rb +2 -2
  108. data/lib/rad/tasks.rb +2 -2
  109. data/lib/rad/template/_context.rb +15 -15
  110. data/lib/rad/template/_relative_path_resolver.rb +1 -1
  111. data/lib/rad/template/_support/tilt.rb +17 -17
  112. data/lib/rad/template/_support/tilt_fixes.rb +3 -3
  113. data/lib/rad/template/_template.rb +47 -47
  114. data/lib/rad/web/_ajax_helper.rb +4 -4
  115. data/lib/rad/web/_controller_miscellaneous_helper.rb +5 -5
  116. data/lib/rad/web/_ensure_no_www.rb +5 -5
  117. data/lib/rad/web/_protect_from_forgery.rb +18 -18
  118. data/lib/rad/web/_require.rb +7 -7
  119. data/lib/rad/web/_router/abstract_routing_helper.rb +4 -4
  120. data/lib/rad/web/_router/controller_routing_helper.rb +15 -15
  121. data/lib/rad/web/_router/view_routing_helper.rb +12 -12
  122. data/readme.md +5 -5
  123. data/spec/controller/abstract_spec.rb +29 -29
  124. data/spec/controller/context_spec.rb +32 -32
  125. data/spec/controller/error_handling_spec.rb +31 -31
  126. data/spec/controller/helper_spec.rb +13 -13
  127. data/spec/controller/http_spec.rb +32 -32
  128. data/spec/controller/render_spec.rb +59 -59
  129. data/spec/conveyors/conveyors_spec.rb +32 -32
  130. data/spec/environment/config_spec.rb +6 -6
  131. data/spec/environment/environment_spec.rb +7 -7
  132. data/spec/environment/minimal_app_spec.rb +4 -4
  133. data/spec/environment/standard_app_spec.rb +10 -10
  134. data/spec/html/basic_html_helper_spec.rb +6 -6
  135. data/spec/html/form_helper_spec.rb +5 -5
  136. data/spec/html/javascript_helper_spec.rb +4 -4
  137. data/spec/html/model_helper_spec.rb +12 -12
  138. data/spec/html/scoped_params_spec.rb +2 -2
  139. data/spec/html/spec_helper.rb +3 -3
  140. data/spec/http/http_spec.rb +9 -9
  141. data/spec/http/miscellaneous_spec.rb +2 -2
  142. data/spec/mailer/mail_controller_spec.rb +23 -23
  143. data/spec/remote/remote_spec.rb +26 -26
  144. data/spec/router/alias_router_spec.rb +22 -22
  145. data/spec/router/basic_router_spec.rb +8 -8
  146. data/spec/router/configurator_spec.rb +4 -4
  147. data/spec/router/integration_spec.rb +17 -17
  148. data/spec/router/object_router_spec.rb +47 -47
  149. data/spec/router/persistent_params_spec.rb +18 -18
  150. data/spec/router/restful_router_spec.rb +39 -39
  151. data/spec/router/router_spec.rb +37 -37
  152. data/spec/router/routing_helper_spec.rb +18 -18
  153. data/spec/support/filters_spec.rb +11 -13
  154. data/spec/template/template_spec.rb +43 -45
  155. data/spec/template/template_spec/views/layout/content_for/content.erb +3 -1
  156. data/spec/template/template_spec/views/layout/content_for/layout.erb +1 -1
  157. data/spec/template/tilt_spec.rb +24 -24
  158. data/spec/web/basic_spec.rb +25 -25
  159. data/spec/web/controller_routing_helper_spec.rb +26 -26
  160. data/spec/web/flash_spec.rb +31 -31
  161. data/spec/web/protect_from_forgery_spec.rb +44 -44
  162. data/spec/web/spec_helper_spec.rb +16 -16
  163. data/spec/web/view_routing_helper_spec.rb +31 -31
  164. metadata +46 -49
  165. data/lib/rad/_support/callbacks.rb +0 -166
  166. data/lib/rad/_support/ruby_ext_with_active_support.rb +0 -4
  167. data/spec/support/callbacks_spec.rb +0 -157
@@ -1,51 +1,51 @@
1
1
  class Rad::Router::BasicRouter
2
2
  include Rad::Router::AbstractRouter
3
3
  inject workspace: :workspace, logger: :logger
4
-
4
+
5
5
  attr_accessor :skip_routes, :redirect_routes
6
-
6
+
7
7
  SKIP_DEFAULT = [/^#{rad.http.url_root}\/(favicon|fs|packaged)/]
8
8
 
9
- def initialize
9
+ def initialize
10
10
  self.skip_routes = SKIP_DEFAULT.clone
11
11
  self.redirect_routes = []
12
12
  end
13
-
13
+
14
14
  def skip path_regexp
15
15
  path_regexp.must_be.a Regexp
16
16
  skip_routes << path_regexp unless skip_routes.include? path_regexp
17
17
  end
18
-
18
+
19
19
  def redirect path_regexp, processor
20
20
  path_regexp.must_be.a Regexp
21
21
  processor.must_be.a String, Proc
22
22
  redirect_routes << [path_regexp, processor] unless redirect_routes.include? [path_regexp, processor]
23
23
  end
24
-
24
+
25
25
  def encode *a
26
26
  end
27
-
27
+
28
28
  def decode path, params
29
29
  # skip
30
30
  if skip_routes.any?{|path_regexp| path_regexp =~ path}
31
31
  logger.info "RAD skipping '#{path}'"
32
32
  throw :halt, true
33
33
  end
34
-
34
+
35
35
  # redirect
36
36
  if meta = redirect_routes.find{|path_regexp, processor| path_regexp =~ path}
37
- path_regexp, processor = meta
37
+ path_regexp, processor = meta
38
38
  target = if processor.is_a? String
39
39
  path.sub(path_regexp, processor)
40
40
  else
41
41
  processor.call path
42
42
  end
43
-
43
+
44
44
  response = workspace.response
45
45
  # content_type = Mime[params.format]
46
46
 
47
47
  response.set!(
48
- status: :redirect,
48
+ status: :redirect,
49
49
  # content_type: content_type,
50
50
  body: %(<html><body>You are being <a href="#{target.html_escape if target}">redirected</a>.</body></html>)
51
51
  )
@@ -63,7 +63,7 @@ Rad::Router::Configurator.class_eval do
63
63
  raise "There's no BasicRouter (use config to add it)!" unless basic_router
64
64
  basic_router.skip *a, &b
65
65
  end
66
-
66
+
67
67
  def redirect *a, &b
68
68
  basic_router = @router.routers[:basic_router]
69
69
  raise "There's no BasicRouter (use config to add it)!" unless basic_router
@@ -1,19 +1,19 @@
1
1
  class Rad::Router::Configurator
2
2
  inject router: :router
3
-
3
+
4
4
  def initialize router
5
5
  @router = router
6
- end
7
-
6
+ end
7
+
8
8
  def persistent_params *args
9
9
  args.each{|v| router.persistent_params << v}
10
10
  end
11
-
11
+
12
12
  class << self
13
13
  inject router: :router
14
-
14
+
15
15
  def configure &block
16
16
  block.call Rad::Router::Configurator.new(router)
17
- end
17
+ end
18
18
  end
19
19
  end
@@ -1,14 +1,14 @@
1
1
  module Rad::Router::CoreRoutingHelper
2
2
  inject router: :router
3
3
 
4
- delegate :url_for, :url_for_path, :persist_params, :persist_params?, :dont_persist_params, to: :router
4
+ delegate :url_for, :url_for_path, :persist_params, :persist_params?, :dont_persist_params, to: :router
5
5
 
6
6
  def default_path options = {}
7
7
  url_for_path rad.router.default_path, options.merge(url_root: false)
8
8
  end
9
9
 
10
10
  def return_to_path options = {}
11
- dont_persist_params do
11
+ dont_persist_params do
12
12
  path = params[:_return_to] || workspace.request.session['return_to'] || rad.router.default_path
13
13
  url_for_path path, options.merge(url_root: false)
14
14
  end
@@ -21,7 +21,7 @@ module Rad::Router::CoreRoutingHelper
21
21
  raise "duplicate :id pameter!" if params.include?(:id) or params.include?('id')
22
22
  params[:id] = args.first.to_param
23
23
  end
24
- params
24
+ params
25
25
  end
26
26
 
27
27
  protected
@@ -30,7 +30,7 @@ module Rad::Router::CoreRoutingHelper
30
30
  if m =~ /path$/
31
31
  params = parse_routing_arguments(*args)
32
32
  klass, method = router.encode_method m, params.include?(:id)
33
-
33
+
34
34
  url_for klass, method, params
35
35
  else
36
36
  super m.to_sym, *args, &block
@@ -1,75 +1,75 @@
1
1
  class Rad::Router::ObjectRouter
2
- include Rad::Router::AbstractRouter
2
+ include Rad::Router::AbstractRouter
3
3
 
4
4
  def initialize
5
5
  self.class_to_resource = -> klass {raise ':class_to_resource not specified!'}
6
6
  self.resource_to_class = -> resource {raise ':resource_to_class not specified!'}
7
7
  self.id_to_class = -> id, params {raise ':id_to_class not specified!'}
8
-
8
+
9
9
  self.default_class_method = :all
10
10
  self.default_object_method = :show
11
-
11
+
12
12
  @cached_class_to_resource, @cached_resource_to_class = {}, {}
13
13
  end
14
14
 
15
15
  def configure options = {}
16
16
  raise "can't configure ObjectRouter twice!" if configured?
17
17
  self.configured = true
18
-
18
+
19
19
  # parsing options
20
20
  options.validate_options! :default_class_name, :class_to_resource, :resource_to_class, :id_to_class, :url_root, :prefix
21
-
21
+
22
22
  self.default_class_name = options[:default_class_name] || raise(':default_class_name not provided!')
23
-
23
+
24
24
  self.class_to_resource = options[:class_to_resource] if options.include? :class_to_resource
25
25
  self.resource_to_class = options[:resource_to_class] if options.include? :resource_to_class
26
26
  self.id_to_class = options[:id_to_class] if options.include? :id_to_class
27
-
27
+
28
28
  self.url_root = parse_url_root options
29
29
  self.prefix = parse_prefix options
30
30
  end
31
31
 
32
32
  def encode klass, method, params
33
33
  return nil unless configured?
34
-
35
- id = params[:id]
36
-
34
+
35
+ id = params[:id]
36
+
37
37
  # id and resource
38
38
  path = if id
39
39
  raise ":id can be used with :default_class only (#{klass}, '#{id}')!" if klass != default_class
40
-
40
+
41
41
  params.delete :id
42
- raise ":id must not start from capital letter ('#{id}')!" if id =~ /^[A-Z]/
43
-
42
+ raise ":id must not start from capital letter ('#{id}')!" if id =~ /^[A-Z]/
43
+
44
44
  path = if !method or method == default_object_method
45
45
  "/#{id}"
46
46
  else
47
47
  "/#{id}/#{method}"
48
48
  end
49
- else
50
- resource = cached_class_to_resource klass
51
- raise "no resource for #{klass}!" unless resource
49
+ else
50
+ resource = cached_class_to_resource klass
51
+ raise "no resource for #{klass}!" unless resource
52
52
  raise "resource must start from capital letter (class: #{klass}, resource: '#{resource}')!" unless resource =~ /^[A-Z]/
53
53
 
54
54
  path = if !method or method == default_class_method
55
55
  "/#{resource}"
56
56
  else
57
57
  "/#{resource}/#{method}"
58
- end
58
+ end
59
59
  end
60
-
60
+
61
61
  # prefix
62
62
  path = encode_prefix_params! path, params, prefix if prefix
63
-
63
+
64
64
  # url_root
65
65
  params[:url_root] = url_root if url_root
66
-
66
+
67
67
  [path, params]
68
68
  end
69
69
 
70
- def decode path, params
70
+ def decode path, params
71
71
  return nil unless configured?
72
-
72
+
73
73
  parts = path[1..-1].split('/')
74
74
 
75
75
  # checking 'size' of path
@@ -89,13 +89,13 @@ class Rad::Router::ObjectRouter
89
89
  # id, resource and method
90
90
  if parts.first =~ /^[A-Z]/
91
91
  resource, method = parts
92
- method ||= default_class_method
92
+ method ||= default_class_method
93
93
  method = method.to_sym
94
-
94
+
95
95
  raise "resource must be in plural form ('#{resource}')!" unless resource.pluralize == resource
96
-
97
- klass = cached_resource_to_class resource
98
-
96
+
97
+ klass = cached_resource_to_class resource
98
+
99
99
  raise "no class for '#{resource}' resource!" unless klass
100
100
  else
101
101
  id, method = parts
@@ -103,35 +103,35 @@ class Rad::Router::ObjectRouter
103
103
  method ||= default_object_method
104
104
  method = method.to_sym
105
105
 
106
- # sometimes we need params inside of :id_to_class block,
106
+ # sometimes we need params inside of :id_to_class block,
107
107
  # for example to find out Space before finding Item
108
108
  klass = id_to_class.call id, params
109
-
109
+
110
110
  raise "no class for '#{id}' id!" unless klass
111
-
111
+
112
112
  params[:id] = id
113
- end
113
+ end
114
114
 
115
115
  klass.must_be.a Class
116
116
  return klass, method, params
117
- end
118
-
119
- def encode_method route_method, has_id
117
+ end
118
+
119
+ def encode_method route_method, has_id
120
120
  return nil unless configured?
121
-
121
+
122
122
  token = route_method.sub(/_?path$/, '')
123
123
 
124
124
  if has_id
125
125
  method = token.empty? ? default_object_method : token
126
126
  method = method.to_sym
127
-
127
+
128
128
  return [default_class, method]
129
129
  else
130
130
  token = route_method.sub(/_path$/, '')
131
131
  parts = token.split '_'
132
132
  resource = parts.pop
133
133
  method = parts.empty? ? default_class_method : parts.join('_')
134
-
134
+
135
135
  # class
136
136
  resource = resource.pluralize.camelize
137
137
  klass = cached_resource_to_class resource
@@ -140,7 +140,7 @@ class Rad::Router::ObjectRouter
140
140
 
141
141
  # method
142
142
  method = method.to_sym if method
143
-
143
+
144
144
  return [klass, method]
145
145
  end
146
146
  end
@@ -148,13 +148,13 @@ class Rad::Router::ObjectRouter
148
148
  protected
149
149
  attr_accessor :class_to_resource, :resource_to_class, :id_to_class, :default_class_method, :default_object_method,
150
150
  :prefix, :url_root, :configured, :default_class_name
151
-
151
+
152
152
  def default_class
153
153
  @default_class ||= default_class_name.constantize
154
154
  end
155
-
155
+
156
156
  def configured?; !!@configured end
157
-
157
+
158
158
  def cached_class_to_resource klass
159
159
  unless @cached_class_to_resource.include? klass
160
160
  resource = class_to_resource.call klass
@@ -164,7 +164,7 @@ class Rad::Router::ObjectRouter
164
164
  end
165
165
  @cached_class_to_resource[klass]
166
166
  end
167
-
167
+
168
168
  def cached_resource_to_class resource
169
169
  unless @cached_resource_to_class.include? resource
170
170
  klass = resource_to_class.call resource
@@ -174,11 +174,11 @@ class Rad::Router::ObjectRouter
174
174
  end
175
175
  end
176
176
 
177
-
177
+
178
178
  Rad::Router::Configurator.class_eval do
179
179
  def objects *args, &block
180
- object_router = @router.routers[:object_router]
181
- raise "There's no ObjectRouter (use config to add it)!" unless object_router
180
+ object_router = @router.routers[:object_router]
181
+ raise "There's no ObjectRouter (use config to add it)!" unless object_router
182
182
  object_router.configure *args, &block
183
183
  end
184
184
  end
@@ -1,31 +1,31 @@
1
1
  class Rad::Router
2
2
  end
3
3
 
4
- #
4
+ #
5
5
  # Libraries
6
- #
6
+ #
7
7
  %w(
8
8
  _configurator
9
9
  _simple_router
10
10
  _router
11
- _default_format_processor
12
-
11
+ _default_format_processor
12
+
13
13
  _core_routing_helper
14
14
  ).each{|f| require "rad/router/#{f}"}
15
15
 
16
16
 
17
- #
17
+ #
18
18
  # Routers
19
- #
19
+ #
20
20
  %w(
21
21
  _abstract_router
22
22
  _basic_router
23
23
  _alias_router
24
24
  _restful_router
25
- _object_router
25
+ _object_router
26
26
  ).each{|f| require "rad/router/#{f}"}
27
27
 
28
28
 
29
- #
29
+ #
30
30
  # Helpers
31
31
  #
@@ -9,24 +9,24 @@ class Rad::Router::RestfulRouter
9
9
  # parsing options
10
10
  options.validate_options! :class_name, :url_root, :prefix
11
11
  resource = resource.to_s
12
- resource.must_not =~ /\//
12
+ resource.must_not =~ /\//
13
13
  raise "resource should be in plural form!" unless resource.pluralize == resource
14
14
  class_name = options.delete(:class_name) || raise("no class name!")
15
15
  class_name.must_be.a String
16
16
  url_root = parse_url_root options
17
17
  prefix = parse_prefix options
18
-
18
+
19
19
  # logic
20
20
  meta = Meta.new
21
21
  meta.merge!(
22
- class_name: class_name,
23
- resource: resource,
24
- url_root: url_root,
22
+ class_name: class_name,
23
+ resource: resource,
24
+ url_root: url_root,
25
25
  prefix: prefix
26
- )
27
-
26
+ )
27
+
28
28
  resources.must_not.include(resource.pluralize)
29
- class_names.must_not.include(class_name)
29
+ class_names.must_not.include(class_name)
30
30
  resources[resource.pluralize] = meta
31
31
  resources[resource.singularize] = meta
32
32
  class_names[class_name] = meta
@@ -35,7 +35,7 @@ class Rad::Router::RestfulRouter
35
35
  def encode klass, method, params
36
36
  meta = class_names[klass.name]
37
37
  return nil unless meta
38
-
38
+
39
39
  path = if id = params.delete(:id)
40
40
  "/#{meta[:resource]}/#{id}/#{method}"
41
41
  else
@@ -44,16 +44,16 @@ class Rad::Router::RestfulRouter
44
44
 
45
45
  prefix = meta[:prefix]
46
46
  path = encode_prefix_params! path, params, prefix if prefix
47
-
47
+
48
48
  url_root = meta[:url_root]
49
49
  params[:url_root] = url_root if url_root
50
-
50
+
51
51
  [path, params]
52
52
  end
53
53
 
54
54
  def decode path, params
55
55
  decode_as_object_resource(path, params) || decode_as_static_resource(path, params)
56
- end
56
+ end
57
57
 
58
58
  def encode_method route_method, has_id
59
59
  token = route_method.sub(/_path$/, '')
@@ -64,52 +64,52 @@ class Rad::Router::RestfulRouter
64
64
  return meta.get_class, route_method[0..(i-2)].to_sym
65
65
  end
66
66
  end
67
-
67
+
68
68
  return nil
69
69
  end
70
70
 
71
71
  protected
72
72
  attr_accessor :resources, :class_names
73
-
73
+
74
74
  def decode_as_object_resource path, params
75
75
  parts = path[1..-1].split('/')
76
76
  return nil unless parts.size >= 3
77
-
77
+
78
78
  method, id, resource = parts.pop.to_sym, parts.pop, parts.pop
79
79
  meta = resources[resource]
80
80
  return nil unless meta
81
-
81
+
82
82
  # url_root
83
83
  url_root = meta[:url_root]
84
- return nil if url_root and "/#{parts.shift}" != url_root
85
-
84
+ return nil if url_root and "/#{parts.shift}" != url_root
85
+
86
86
  # prefix
87
87
  return nil if parts.size != (meta[:prefix] ? meta[:prefix].size : 0)
88
88
  prefix = meta[:prefix]
89
89
  decode_prefix_params! parts, params, prefix if prefix
90
-
90
+
91
91
  params[:id] = id
92
92
 
93
93
  return meta.get_class, method, params
94
94
  end
95
-
95
+
96
96
  def decode_as_static_resource path, params
97
- parts = path[1..-1].split('/')
97
+ parts = path[1..-1].split('/')
98
98
  return nil unless parts.size >= 2
99
-
99
+
100
100
  # method & class
101
101
  method, resource = parts.pop.to_sym, parts.pop
102
102
  meta = resources[resource]
103
103
  return nil unless meta
104
-
104
+
105
105
  # url_root
106
106
  url_root = meta[:url_root]
107
- return nil if url_root and "/#{parts.shift}" != url_root
107
+ return nil if url_root and "/#{parts.shift}" != url_root
108
108
 
109
109
  # prefix
110
110
  return nil if parts.size != (meta[:prefix] ? meta[:prefix].size : 0)
111
111
  prefix = meta[:prefix]
112
- decode_prefix_params! parts, params, prefix if prefix
112
+ decode_prefix_params! parts, params, prefix if prefix
113
113
 
114
114
  return meta.get_class, method, params
115
115
  end