Class: ActionDispatch::Routing::Mapper::Scope

Inherits:
Object
  • Object
show all
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, :options]
RESOURCE_SCOPES =
[:resource, :resources]
RESOURCE_METHOD_SCOPES =
[:collection, :member, :new]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Scope.



1901
1902
1903
1904
1905
# File 'lib/action_dispatch/routing/mapper.rb', line 1901

def initialize(hash, parent = {}, scope_level = nil)
  @hash = hash
  @parent = parent
  @scope_level = scope_level
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



1899
1900
1901
# File 'lib/action_dispatch/routing/mapper.rb', line 1899

def parent
  @parent
end

#scope_levelObject (readonly)

Returns the value of attribute scope_level.



1899
1900
1901
# File 'lib/action_dispatch/routing/mapper.rb', line 1899

def scope_level
  @scope_level
end

Instance Method Details

#[](key) ⇒ Object



1956
1957
1958
# File 'lib/action_dispatch/routing/mapper.rb', line 1956

def [](key)
  @hash.fetch(key) { @parent[key] }
end

#[]=(k, v) ⇒ Object



1960
1961
1962
# File 'lib/action_dispatch/routing/mapper.rb', line 1960

def []=(k,v)
  @hash[k] = v
end

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



1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
# File 'lib/action_dispatch/routing/mapper.rb', line 1919

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

#fetch(key, &block) ⇒ Object



1952
1953
1954
# File 'lib/action_dispatch/routing/mapper.rb', line 1952

def fetch(key, &block)
  @hash.fetch(key, &block)
end

#nested?Boolean

Returns:

  • (Boolean)


1907
1908
1909
# File 'lib/action_dispatch/routing/mapper.rb', line 1907

def nested?
  scope_level == :nested
end

#new(hash) ⇒ Object



1944
1945
1946
# File 'lib/action_dispatch/routing/mapper.rb', line 1944

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

#new_level(level) ⇒ Object



1948
1949
1950
# File 'lib/action_dispatch/routing/mapper.rb', line 1948

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

#optionsObject



1940
1941
1942
# File 'lib/action_dispatch/routing/mapper.rb', line 1940

def options
  OPTIONS
end

#resource_method_scope?Boolean

Returns:

  • (Boolean)


1915
1916
1917
# File 'lib/action_dispatch/routing/mapper.rb', line 1915

def resource_method_scope?
  RESOURCE_METHOD_SCOPES.include? scope_level
end

#resource_scope?Boolean

Returns:

  • (Boolean)


1936
1937
1938
# File 'lib/action_dispatch/routing/mapper.rb', line 1936

def resource_scope?
  RESOURCE_SCOPES.include? scope_level
end

#resources?Boolean

Returns:

  • (Boolean)


1911
1912
1913
# File 'lib/action_dispatch/routing/mapper.rb', line 1911

def resources?
  scope_level == :resources
end