Class: ActionDispatch::Routing::Mapper::Scope
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper::Scope
show all
- Includes:
- Enumerable
- Defined in:
- actionpack/lib/action_dispatch/routing/mapper.rb
Overview
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
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole
Constructor Details
#initialize(hash, parent = ROOT, scope_level = nil) ⇒ Scope
Returns a new instance of Scope.
2451
2452
2453
2454
2455
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2451
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
Returns the value of attribute parent.
2449
2450
2451
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2449
def parent
@parent
end
|
#scope_level ⇒ Object
Returns the value of attribute scope_level.
2449
2450
2451
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2449
def scope_level
@scope_level
end
|
Instance Method Details
2510
2511
2512
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2510
def [](key)
frame[key]
end
|
#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2477
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
|
2518
2519
2520
2521
2522
2523
2524
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2518
def each
node = self
until node.equal? ROOT
yield node
node = node.parent
end
end
|
2514
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2514
def frame; @hash; end
|
#nested? ⇒ Boolean
2457
2458
2459
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2457
def nested?
scope_level == :nested
end
|
#new(hash) ⇒ Object
2502
2503
2504
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2502
def new(hash)
self.class.new hash, self, scope_level
end
|
#new_level(level) ⇒ Object
2506
2507
2508
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2506
def new_level(level)
self.class.new(frame, self, level)
end
|
#null? ⇒ Boolean
2461
2462
2463
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2461
def null?
@hash.nil? && @parent.nil?
end
|
2498
2499
2500
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2498
def options
OPTIONS
end
|
#resource_method_scope? ⇒ Boolean
2473
2474
2475
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2473
def resource_method_scope?
RESOURCE_METHOD_SCOPES.include? scope_level
end
|
#resource_scope? ⇒ Boolean
2494
2495
2496
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2494
def resource_scope?
RESOURCE_SCOPES.include? scope_level
end
|
#resources? ⇒ Boolean
2469
2470
2471
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2469
def resources?
scope_level == :resources
end
|
#root? ⇒ Boolean
2465
2466
2467
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2465
def root?
@parent == ROOT
end
|