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]
- NULL =
Scope.new(nil, nil)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #compact_blank, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pluck, #sum, #without
Constructor Details
#initialize(hash, parent = NULL, scope_level = nil) ⇒ Scope
Returns a new instance of Scope.
2234
2235
2236
2237
2238
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2234
def initialize(hash, parent = NULL, scope_level = nil)
@hash = hash
@parent = parent
@scope_level = scope_level
end
|
Instance Attribute Details
Returns the value of attribute parent
2232
2233
2234
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2232
def parent
@parent
end
|
#scope_level ⇒ Object
Returns the value of attribute scope_level
2232
2233
2234
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2232
def scope_level
@scope_level
end
|
Instance Method Details
2293
2294
2295
2296
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2293
def [](key)
scope = find { |node| node.frame.key? key }
scope && scope.frame[key]
end
|
#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2260
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
|
2300
2301
2302
2303
2304
2305
2306
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2300
def each
node = self
until node.equal? NULL
yield node
node = node.parent
end
end
|
2308
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2308
def frame; @hash; end
|
#nested? ⇒ Boolean
2240
2241
2242
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2240
def nested?
scope_level == :nested
end
|
#new(hash) ⇒ Object
2285
2286
2287
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2285
def new(hash)
self.class.new hash, self, scope_level
end
|
#new_level(level) ⇒ Object
2289
2290
2291
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2289
def new_level(level)
self.class.new(frame, self, level)
end
|
#null? ⇒ Boolean
2244
2245
2246
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2244
def null?
@hash.nil? && @parent.nil?
end
|
2281
2282
2283
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2281
def options
OPTIONS
end
|
#resource_method_scope? ⇒ Boolean
2256
2257
2258
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2256
def resource_method_scope?
RESOURCE_METHOD_SCOPES.include? scope_level
end
|
#resource_scope? ⇒ Boolean
2277
2278
2279
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2277
def resource_scope?
RESOURCE_SCOPES.include? scope_level
end
|
#resources? ⇒ Boolean
2252
2253
2254
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2252
def resources?
scope_level == :resources
end
|
#root? ⇒ Boolean
2248
2249
2250
|
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2248
def root?
@parent.null?
end
|