Class: ActionDispatch::Routing::Mapper::Scope

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(hash, parent = NULL, scope_level = nil) ⇒ Scope

Returns a new instance of Scope.



2161
2162
2163
2164
2165
# File 'lib/action_dispatch/routing/mapper.rb', line 2161

def initialize(hash, parent = NULL, scope_level = nil)
  @hash = hash
  @parent = parent
  @scope_level = scope_level
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



2159
2160
2161
# File 'lib/action_dispatch/routing/mapper.rb', line 2159

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.



2159
2160
2161
# File 'lib/action_dispatch/routing/mapper.rb', line 2159

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object



2220
2221
2222
2223
# File 'lib/action_dispatch/routing/mapper.rb', line 2220

def [](key)
  scope = find { |node| node.frame.key? key }
  scope && scope.frame[key]
end

#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object



2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
# File 'lib/action_dispatch/routing/mapper.rb', line 2187

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

#eachObject



2227
2228
2229
2230
2231
2232
2233
# File 'lib/action_dispatch/routing/mapper.rb', line 2227

def each
  node = self
  until node.equal? NULL
    yield node
    node = node.parent
  end
end

#frameObject



2235
# File 'lib/action_dispatch/routing/mapper.rb', line 2235

def frame; @hash; end

#nested?Boolean

Returns:

  • (Boolean)


2167
2168
2169
# File 'lib/action_dispatch/routing/mapper.rb', line 2167

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object



2212
2213
2214
# File 'lib/action_dispatch/routing/mapper.rb', line 2212

def new(hash)
  self.class.new hash, self, scope_level
end

#new_level(level) ⇒ Object



2216
2217
2218
# File 'lib/action_dispatch/routing/mapper.rb', line 2216

def new_level(level)
  self.class.new(frame, self, level)
end

#null?Boolean

Returns:

  • (Boolean)


2171
2172
2173
# File 'lib/action_dispatch/routing/mapper.rb', line 2171

def null?
  @hash.nil? && @parent.nil?
end

#optionsObject



2208
2209
2210
# File 'lib/action_dispatch/routing/mapper.rb', line 2208

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)


2183
2184
2185
# File 'lib/action_dispatch/routing/mapper.rb', line 2183

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)


2204
2205
2206
# File 'lib/action_dispatch/routing/mapper.rb', line 2204

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)


2179
2180
2181
# File 'lib/action_dispatch/routing/mapper.rb', line 2179

def resources?
  scope_level == :resources
end

#root?Boolean

Returns:

  • (Boolean)


2175
2176
2177
# File 'lib/action_dispatch/routing/mapper.rb', line 2175

def root?
  @parent.null?
end