Class: ActionController::Routing::ControllerComponent
Overview
Instance Attribute Summary
#condition, #default
Class Method Summary
collapse
Instance Method Summary
collapse
#default_check, #dynamic?, #initialize, #optional?, #write_continue_generation, #write_dropout_generation, #write_generation, #write_recognition
Methods inherited from Component
#dynamic?, new, #optional?
Class Method Details
.assign_controller(g, controller) ⇒ Object
217
218
219
220
|
# File 'lib/action_controller/routing.rb', line 217
def assign_controller(g, controller)
expr = "::#{controller.split('/').collect {|c| c.camelize}.join('::')}Controller"
g.result :controller, expr, true
end
|
.traverse_to_controller(segments, start_at = 0) ⇒ Object
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
# File 'lib/action_controller/routing.rb', line 222
def traverse_to_controller(segments, start_at = 0)
mod = ::Object
length = segments.length
index = start_at
mod_name = controller_name = segment = nil
while index < length
return nil unless /\A[A-Za-z][A-Za-z\d_]*\Z/ =~ (segment = segments[index])
index += 1
mod_name = segment.camelize
controller_name = "#{mod_name}Controller"
path_suffix = File.join(segments[start_at..(index - 1)])
next_mod = nil
if mod.const_defined?(controller_name) || attempt_load(mod, controller_name, path_suffix + "_controller") == :defined
controller = mod.const_get(controller_name)
return nil unless controller.is_a?(Class) && controller.ancestors.include?(ActionController::Base) return [controller, (index - start_at)]
end
if mod.const_defined? mod_name
next_mod = mod.send(:const_get, mod_name)
next_mod = nil unless next_mod.is_a?(Module)
else
case attempt_load(mod, mod_name, path_suffix)
when :defined then next_mod = mod.const_get mod_name
when :dir then next_mod = Module.new mod.send :const_set, mod_name, next_mod
else
return nil
end
end
mod = next_mod
return nil unless mod && mod.is_a?(Module)
end
nil
end
|
Instance Method Details
#add_segments_to(g) ⇒ Object
188
189
190
|
# File 'lib/action_controller/routing.rb', line 188
def add_segments_to(g)
g.add_segment(%(\#{#{g.hash_value(key, true, default)}})) {|gp| yield gp}
end
|
#assign_default(g) ⇒ Object
#assign_result(g) {|g| ... } ⇒ Object
207
208
209
210
|
# File 'lib/action_controller/routing.rb', line 207
def assign_result(g)
g.result key, 'controller_value'
yield g
end
|
#key ⇒ Object
186
|
# File 'lib/action_controller/routing.rb', line 186
def key() :controller end
|
#recognition_check(g) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/action_controller/routing.rb', line 192
def recognition_check(g)
g << "controller_result = ::ActionController::Routing::ControllerComponent.traverse_to_controller(#{g.path_name}, #{g.index_name})"
g.if('controller_result') do |gp|
gp << 'controller_value, segments_to_controller = controller_result'
if condition
gp << "controller_path = #{gp.path_name}[#{gp.index_name},segments_to_controller].join('/')"
gp.if(Routing.test_condition("controller_path", condition)) do |gpp|
gpp.move_forward('segments_to_controller') {|gppp| yield gppp, :constraint}
end
else
gp.move_forward('segments_to_controller') {|gpp| yield gpp, :constraint}
end
end
end
|