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.



2224
2225
2226
2227
2228
# File 'lib/action_dispatch/routing/mapper.rb', line 2224

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.



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

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.



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

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object



2283
2284
2285
2286
# File 'lib/action_dispatch/routing/mapper.rb', line 2283

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

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



2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
# File 'lib/action_dispatch/routing/mapper.rb', line 2250

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



2290
2291
2292
2293
2294
2295
2296
# File 'lib/action_dispatch/routing/mapper.rb', line 2290

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

#frameObject



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

def frame; @hash; end

#nested?Boolean

Returns:

  • (Boolean)


2230
2231
2232
# File 'lib/action_dispatch/routing/mapper.rb', line 2230

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object



2275
2276
2277
# File 'lib/action_dispatch/routing/mapper.rb', line 2275

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

#new_level(level) ⇒ Object



2279
2280
2281
# File 'lib/action_dispatch/routing/mapper.rb', line 2279

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

#null?Boolean

Returns:

  • (Boolean)


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

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

#optionsObject



2271
2272
2273
# File 'lib/action_dispatch/routing/mapper.rb', line 2271

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)


2246
2247
2248
# File 'lib/action_dispatch/routing/mapper.rb', line 2246

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)


2267
2268
2269
# File 'lib/action_dispatch/routing/mapper.rb', line 2267

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)


2242
2243
2244
# File 'lib/action_dispatch/routing/mapper.rb', line 2242

def resources?
  scope_level == :resources
end

#root?Boolean

Returns:

  • (Boolean)


2238
2239
2240
# File 'lib/action_dispatch/routing/mapper.rb', line 2238

def root?
  @parent.null?
end