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.
2300
2301
2302
2303
2304
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2300
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.
2298
2299
2300
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2298
def parent
@parent
end
|
#scope_level ⇒ Object
Returns the value of attribute scope_level.
2298
2299
2300
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2298
def scope_level
@scope_level
end
|
Instance Method Details
2359
2360
2361
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2359
def [](key)
frame[key]
end
|
#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2326
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
|
2367
2368
2369
2370
2371
2372
2373
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2367
def each
node = self
until node.equal? ROOT
yield node
node = node.parent
end
end
|
2363
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2363
def frame; @hash; end
|
#nested? ⇒ Boolean
2306
2307
2308
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2306
def nested?
scope_level == :nested
end
|
#new(hash) ⇒ Object
2351
2352
2353
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2351
def new(hash)
self.class.new hash, self, scope_level
end
|
#new_level(level) ⇒ Object
2355
2356
2357
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2355
def new_level(level)
self.class.new(frame, self, level)
end
|
#null? ⇒ Boolean
2310
2311
2312
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2310
def null?
@hash.nil? && @parent.nil?
end
|
2347
2348
2349
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2347
def options
OPTIONS
end
|
#resource_method_scope? ⇒ Boolean
2322
2323
2324
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2322
def resource_method_scope?
RESOURCE_METHOD_SCOPES.include? scope_level
end
|
#resource_scope? ⇒ Boolean
2343
2344
2345
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2343
def resource_scope?
RESOURCE_SCOPES.include? scope_level
end
|
#resources? ⇒ Boolean
2318
2319
2320
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2318
def resources?
scope_level == :resources
end
|
#root? ⇒ Boolean
2314
2315
2316
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2314
def root?
@parent == ROOT
end
|