Class: ActionDispatch::Routing::Mapper::Scope
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper::Scope
- 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
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#scope_level ⇒ Object
readonly
Returns the value of attribute scope_level.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(k, v) ⇒ Object
- #action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
- #fetch(key, &block) ⇒ Object
-
#initialize(hash, parent = {}, scope_level = nil) ⇒ Scope
constructor
A new instance of Scope.
- #nested? ⇒ Boolean
- #new(hash) ⇒ Object
- #new_level(level) ⇒ Object
- #options ⇒ Object
- #resource_method_scope? ⇒ Boolean
- #resource_scope? ⇒ Boolean
- #resources? ⇒ Boolean
Constructor Details
#initialize(hash, parent = {}, scope_level = nil) ⇒ Scope
Returns a new instance of Scope.
1900 1901 1902 1903 1904 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1900 def initialize(hash, parent = {}, scope_level = nil) @hash = hash @parent = parent @scope_level = scope_level end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
1898 1899 1900 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1898 def parent @parent end |
#scope_level ⇒ Object (readonly)
Returns the value of attribute scope_level.
1898 1899 1900 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1898 def scope_level @scope_level end |
Instance Method Details
#[](key) ⇒ Object
1955 1956 1957 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1955 def [](key) @hash.fetch(key) { @parent[key] } end |
#[]=(k, v) ⇒ Object
1959 1960 1961 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1959 def []=(k,v) @hash[k] = v end |
#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1918 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
1951 1952 1953 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1951 def fetch(key, &block) @hash.fetch(key, &block) end |
#nested? ⇒ Boolean
1906 1907 1908 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1906 def nested? scope_level == :nested end |
#new(hash) ⇒ Object
1943 1944 1945 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1943 def new(hash) self.class.new hash, self, scope_level end |
#new_level(level) ⇒ Object
1947 1948 1949 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1947 def new_level(level) self.class.new(self, self, level) end |
#options ⇒ Object
1939 1940 1941 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1939 def OPTIONS end |
#resource_method_scope? ⇒ Boolean
1914 1915 1916 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1914 def resource_method_scope? RESOURCE_METHOD_SCOPES.include? scope_level end |
#resource_scope? ⇒ Boolean
1935 1936 1937 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1935 def resource_scope? RESOURCE_SCOPES.include? scope_level end |
#resources? ⇒ Boolean
1910 1911 1912 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1910 def resources? scope_level == :resources end |