Class: ActionDispatch::Routing::Mapper::Scope
- Includes:
- Enumerable
- Defined in:
- actionpack/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]
- NULL =
Scope.new(nil, 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 = NULL, 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
Methods included from Enumerable
#as_json, #exclude?, #index_by, #many?, #pluck, #sum, #without
Constructor Details
#initialize(hash, parent = NULL, scope_level = nil) ⇒ Scope
Returns a new instance of Scope.
2162 2163 2164 2165 2166 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2162 def initialize(hash, parent = NULL, scope_level = nil) @hash = hash @parent = parent @scope_level = scope_level end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
2160 2161 2162 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2160 def parent @parent end |
#scope_level ⇒ Object (readonly)
Returns the value of attribute scope_level.
2160 2161 2162 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2160 def scope_level @scope_level end |
Instance Method Details
#[](key) ⇒ Object
2221 2222 2223 2224 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2221 def [](key) scope = find { |node| node.frame.key? key } scope && scope.frame[key] end |
#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2188 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
2228 2229 2230 2231 2232 2233 2234 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2228 def each node = self until node.equal? NULL yield node node = node.parent end end |
#frame ⇒ Object
2236 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2236 def frame; @hash; end |
#nested? ⇒ Boolean
2168 2169 2170 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2168 def nested? scope_level == :nested end |
#new(hash) ⇒ Object
2213 2214 2215 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2213 def new(hash) self.class.new hash, self, scope_level end |
#new_level(level) ⇒ Object
2217 2218 2219 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2217 def new_level(level) self.class.new(frame, self, level) end |
#null? ⇒ Boolean
2172 2173 2174 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2172 def null? @hash.nil? && @parent.nil? end |
#options ⇒ Object
2209 2210 2211 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2209 def OPTIONS end |
#resource_method_scope? ⇒ Boolean
2184 2185 2186 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2184 def resource_method_scope? RESOURCE_METHOD_SCOPES.include? scope_level end |
#resource_scope? ⇒ Boolean
2205 2206 2207 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2205 def resource_scope? RESOURCE_SCOPES.include? scope_level end |
#resources? ⇒ Boolean
2180 2181 2182 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2180 def resources? scope_level == :resources end |
#root? ⇒ Boolean
2176 2177 2178 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2176 def root? @parent.null? end |