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.



2048
2049
2050
2051
2052
# File 'lib/action_dispatch/routing/mapper.rb', line 2048

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.



2046
2047
2048
# File 'lib/action_dispatch/routing/mapper.rb', line 2046

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.



2046
2047
2048
# File 'lib/action_dispatch/routing/mapper.rb', line 2046

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object



2099
2100
2101
2102
# File 'lib/action_dispatch/routing/mapper.rb', line 2099

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

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



2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
# File 'lib/action_dispatch/routing/mapper.rb', line 2066

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



2106
2107
2108
2109
2110
2111
2112
2113
# File 'lib/action_dispatch/routing/mapper.rb', line 2106

def each
  node = self
  loop do
    break if node.equal? NULL
    yield node
    node = node.parent
  end
end

#frameObject



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

def frame; @hash; end

#nested?Boolean

Returns:

  • (Boolean)


2054
2055
2056
# File 'lib/action_dispatch/routing/mapper.rb', line 2054

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object



2091
2092
2093
# File 'lib/action_dispatch/routing/mapper.rb', line 2091

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

#new_level(level) ⇒ Object



2095
2096
2097
# File 'lib/action_dispatch/routing/mapper.rb', line 2095

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

#optionsObject



2087
2088
2089
# File 'lib/action_dispatch/routing/mapper.rb', line 2087

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)


2062
2063
2064
# File 'lib/action_dispatch/routing/mapper.rb', line 2062

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)


2083
2084
2085
# File 'lib/action_dispatch/routing/mapper.rb', line 2083

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)


2058
2059
2060
# File 'lib/action_dispatch/routing/mapper.rb', line 2058

def resources?
  scope_level == :resources
end