Class: ActionDispatch::Routing::Mapper::Scope
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper::Scope
- Includes:
- Enumerable
- Defined in:
- lib/action_dispatch/routing/mapper.rb
Overview
:nodoc:
Constant Summary collapse
- OPTIONS =
[:path, :shallow_path, :as, :shallow_prefix, :module, :controller, :action, :path_names, :constraints, :shallow, :blocks, :defaults, :via, :format, :options, :to]
- RESOURCE_SCOPES =
[:resource, :resources]
- RESOURCE_METHOD_SCOPES =
[:collection, :member, :new]
- ROOT =
Scope.new({}, nil)
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#scope_level ⇒ Object
readonly
Returns the value of attribute scope_level.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
- #each ⇒ Object
- #frame ⇒ Object
-
#initialize(hash, parent = ROOT, scope_level = nil) ⇒ Scope
constructor
A new instance of Scope.
- #nested? ⇒ Boolean
- #new(hash) ⇒ Object
- #new_level(level) ⇒ Object
- #null? ⇒ Boolean
- #options ⇒ Object
- #resource_method_scope? ⇒ Boolean
- #resource_scope? ⇒ Boolean
- #resources? ⇒ Boolean
- #root? ⇒ Boolean
Constructor Details
#initialize(hash, parent = ROOT, scope_level = nil) ⇒ Scope
Returns a new instance of Scope.
2450 2451 2452 2453 2454 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2450 def initialize(hash, parent = ROOT, scope_level = nil) @parent = parent @hash = parent ? parent.frame.merge(hash) : hash @scope_level = scope_level end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
2448 2449 2450 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2448 def parent @parent end |
#scope_level ⇒ Object (readonly)
Returns the value of attribute scope_level.
2448 2449 2450 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2448 def scope_level @scope_level end |
Instance Method Details
#[](key) ⇒ Object
2509 2510 2511 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2509 def [](key) frame[key] end |
#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2476 def action_name(name_prefix, prefix, collection_name, member_name) case scope_level when :nested [name_prefix, prefix] when :collection [prefix, name_prefix, collection_name] when :new [prefix, :new, name_prefix, member_name] when :member [prefix, name_prefix, member_name] when :root [name_prefix, collection_name, prefix] else [name_prefix, member_name, prefix] end end |
#each ⇒ Object
2517 2518 2519 2520 2521 2522 2523 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2517 def each node = self until node.equal? ROOT yield node node = node.parent end end |
#frame ⇒ Object
2513 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2513 def frame; @hash; end |
#nested? ⇒ Boolean
2456 2457 2458 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2456 def nested? scope_level == :nested end |
#new(hash) ⇒ Object
2501 2502 2503 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2501 def new(hash) self.class.new hash, self, scope_level end |
#new_level(level) ⇒ Object
2505 2506 2507 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2505 def new_level(level) self.class.new(frame, self, level) end |
#null? ⇒ Boolean
2460 2461 2462 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2460 def null? @hash.nil? && @parent.nil? end |
#options ⇒ Object
2497 2498 2499 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2497 def OPTIONS end |
#resource_method_scope? ⇒ Boolean
2472 2473 2474 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2472 def resource_method_scope? RESOURCE_METHOD_SCOPES.include? scope_level end |
#resource_scope? ⇒ Boolean
2493 2494 2495 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2493 def resource_scope? RESOURCE_SCOPES.include? scope_level end |
#resources? ⇒ Boolean
2468 2469 2470 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2468 def resources? scope_level == :resources end |
#root? ⇒ Boolean
2464 2465 2466 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2464 def root? @parent == ROOT end |