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.



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

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.



2269
2270
2271
# File 'lib/action_dispatch/routing/mapper.rb', line 2269

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.



2269
2270
2271
# File 'lib/action_dispatch/routing/mapper.rb', line 2269

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object



2330
2331
2332
2333
# File 'lib/action_dispatch/routing/mapper.rb', line 2330

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

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



2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
# File 'lib/action_dispatch/routing/mapper.rb', line 2297

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



2337
2338
2339
2340
2341
2342
2343
# File 'lib/action_dispatch/routing/mapper.rb', line 2337

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

#frameObject



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

def frame; @hash; end

#nested?Boolean

Returns:

  • (Boolean)


2277
2278
2279
# File 'lib/action_dispatch/routing/mapper.rb', line 2277

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object



2322
2323
2324
# File 'lib/action_dispatch/routing/mapper.rb', line 2322

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

#new_level(level) ⇒ Object



2326
2327
2328
# File 'lib/action_dispatch/routing/mapper.rb', line 2326

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

#null?Boolean

Returns:

  • (Boolean)


2281
2282
2283
# File 'lib/action_dispatch/routing/mapper.rb', line 2281

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

#optionsObject



2318
2319
2320
# File 'lib/action_dispatch/routing/mapper.rb', line 2318

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)


2293
2294
2295
# File 'lib/action_dispatch/routing/mapper.rb', line 2293

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)


2314
2315
2316
# File 'lib/action_dispatch/routing/mapper.rb', line 2314

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)


2289
2290
2291
# File 'lib/action_dispatch/routing/mapper.rb', line 2289

def resources?
  scope_level == :resources
end

#root?Boolean

Returns:

  • (Boolean)


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

def root?
  @parent.null?
end