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]
ROOT =
Scope.new({}, 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

Constructor Details

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

Returns a new instance of Scope.



2448
2449
2450
2451
2452
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2448

def initialize(hash, parent = ROOT, scope_level = nil)
  @parent = parent
  @hash = parent ? parent.frame.merge(hash) : hash
  @scope_level = scope_level
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



2446
2447
2448
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2446

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.



2446
2447
2448
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2446

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object



2507
2508
2509
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2507

def [](key)
  frame[key]
end

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



2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2474

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



2515
2516
2517
2518
2519
2520
2521
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2515

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

#frameObject



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

def frame; @hash; end

#nested?Boolean

Returns:

  • (Boolean)


2454
2455
2456
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2454

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object



2499
2500
2501
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2499

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

#new_level(level) ⇒ Object



2503
2504
2505
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2503

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

#null?Boolean

Returns:

  • (Boolean)


2458
2459
2460
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2458

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

#optionsObject



2495
2496
2497
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2495

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)


2470
2471
2472
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2470

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)


2491
2492
2493
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2491

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)


2466
2467
2468
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2466

def resources?
  scope_level == :resources
end

#root?Boolean

Returns:

  • (Boolean)


2462
2463
2464
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2462

def root?
  @parent == ROOT
end