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]
- 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
Constructor Details
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
2146 2147 2148 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2146 def parent @parent end |
#scope_level ⇒ Object (readonly)
Returns the value of attribute scope_level.
2146 2147 2148 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2146 def scope_level @scope_level end |
Instance Method Details
#[](key) ⇒ Object
2207 2208 2209 2210 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2207 def [](key) scope = find { |node| node.frame.key? key } scope && scope.frame[key] end |
#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2174 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
2214 2215 2216 2217 2218 2219 2220 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2214 def each node = self until node.equal? NULL yield node node = node.parent end end |
#frame ⇒ Object
2222 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2222 def frame; @hash; end |
#nested? ⇒ Boolean
2154 2155 2156 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2154 def nested? scope_level == :nested end |
#new(hash) ⇒ Object
2199 2200 2201 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2199 def new(hash) self.class.new hash, self, scope_level end |
#new_level(level) ⇒ Object
2203 2204 2205 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2203 def new_level(level) self.class.new(frame, self, level) end |
#null? ⇒ Boolean
2158 2159 2160 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2158 def null? @hash.nil? && @parent.nil? end |
#options ⇒ Object
2195 2196 2197 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2195 def OPTIONS end |
#resource_method_scope? ⇒ Boolean
2170 2171 2172 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2170 def resource_method_scope? RESOURCE_METHOD_SCOPES.include? scope_level end |
#resource_scope? ⇒ Boolean
2191 2192 2193 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2191 def resource_scope? RESOURCE_SCOPES.include? scope_level end |
#resources? ⇒ Boolean
2166 2167 2168 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2166 def resources? scope_level == :resources end |
#root? ⇒ Boolean
2162 2163 2164 |
# File 'lib/action_dispatch/routing/mapper.rb', line 2162 def root? @parent.null? end |