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.
1902 1903 1904 1905 1906 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1902 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.
1900 1901 1902 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1900 def parent @parent end |
#scope_level ⇒ Object (readonly)
Returns the value of attribute scope_level.
1900 1901 1902 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1900 def scope_level @scope_level end |
Instance Method Details
#[](key) ⇒ Object
1957 1958 1959 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1957 def [](key) @hash.fetch(key) { @parent[key] } end |
#[]=(k, v) ⇒ Object
1961 1962 1963 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1961 def []=(k,v) @hash[k] = v end |
#action_name(name_prefix, prefix, collection_name, member_name) ⇒ Object
1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1920 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
1953 1954 1955 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1953 def fetch(key, &block) @hash.fetch(key, &block) end |
#nested? ⇒ Boolean
1908 1909 1910 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1908 def nested? scope_level == :nested end |
#new(hash) ⇒ Object
1945 1946 1947 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1945 def new(hash) self.class.new hash, self, scope_level end |
#new_level(level) ⇒ Object
1949 1950 1951 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1949 def new_level(level) self.class.new(self, self, level) end |
#options ⇒ Object
1941 1942 1943 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1941 def OPTIONS end |
#resource_method_scope? ⇒ Boolean
1916 1917 1918 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1916 def resource_method_scope? RESOURCE_METHOD_SCOPES.include? scope_level end |
#resource_scope? ⇒ Boolean
1937 1938 1939 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1937 def resource_scope? RESOURCE_SCOPES.include? scope_level end |
#resources? ⇒ Boolean
1912 1913 1914 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1912 def resources? scope_level == :resources end |