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

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

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole, #sum

Constructor Details

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

Returns a new instance of Scope.


2200
2201
2202
2203
2204
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2200

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.


2198
2199
2200
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2198

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.


2198
2199
2200
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2198

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object


2259
2260
2261
2262
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2259

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

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


2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2226

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


2266
2267
2268
2269
2270
2271
2272
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2266

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

#frameObject


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

def frame; @hash; end

#nested?Boolean

Returns:

  • (Boolean)

2206
2207
2208
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2206

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object


2251
2252
2253
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2251

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

#new_level(level) ⇒ Object


2255
2256
2257
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2255

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

#null?Boolean

Returns:

  • (Boolean)

2210
2211
2212
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2210

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

#optionsObject


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

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)

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

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)

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

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)

2218
2219
2220
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2218

def resources?
  scope_level == :resources
end

#root?Boolean

Returns:

  • (Boolean)

2214
2215
2216
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2214

def root?
  @parent.null?
end