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.



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

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.



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

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.



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

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object



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

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

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



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

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



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

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

#frameObject



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

def frame; @hash; end

#nested?Boolean

Returns:

  • (Boolean)


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

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object



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

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

#new_level(level) ⇒ Object



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

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

#optionsObject



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

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)


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

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)


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

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)


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

def resources?
  scope_level == :resources
end