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.



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

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.



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

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.



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

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object



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

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

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



2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
# File 'lib/action_dispatch/routing/mapper.rb', line 2079

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



2119
2120
2121
2122
2123
2124
2125
2126
# File 'lib/action_dispatch/routing/mapper.rb', line 2119

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

#frameObject



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

def frame; @hash; end

#nested?Boolean

Returns:

  • (Boolean)


2067
2068
2069
# File 'lib/action_dispatch/routing/mapper.rb', line 2067

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object



2104
2105
2106
# File 'lib/action_dispatch/routing/mapper.rb', line 2104

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

#new_level(level) ⇒ Object



2108
2109
2110
# File 'lib/action_dispatch/routing/mapper.rb', line 2108

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

#optionsObject



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

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)


2075
2076
2077
# File 'lib/action_dispatch/routing/mapper.rb', line 2075

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)


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

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)


2071
2072
2073
# File 'lib/action_dispatch/routing/mapper.rb', line 2071

def resources?
  scope_level == :resources
end