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