Class: ResourcesController::SingletonSpecification
- Inherits:
-
Specification
- Object
- Specification
- ResourcesController::SingletonSpecification
- Defined in:
- lib/resources_controller/specification.rb
Overview
A Singleton Specification
Instance Attribute Summary
Attributes inherited from Specification
#as, #find, #klass, #name, #name_prefix, #segment, #source
Instance Method Summary collapse
-
#find_resource(controller) ⇒ Object
finds the resource from the enclosing resource.
-
#initialize(spec_name, options = {}, &block) ⇒ SingletonSpecification
constructor
Same as Specification except: .
-
#key ⇒ Object
no key for singleton resources.
-
#singleton? ⇒ Boolean
returns true.
Methods inherited from Specification
Constructor Details
#initialize(spec_name, options = {}, &block) ⇒ SingletonSpecification
Same as Specification except:
Options for unconvential use (otherwise these are all inferred from the name)
-
:source:
a singular string or symbol (e.g. :blog). This is used to find the class or association name -
:segment:
(e.g. ‘blog’) the segment name in the route that is matched
96 97 98 99 100 101 |
# File 'lib/resources_controller/specification.rb', line 96 def initialize(spec_name, = {}, &block) [:segment] ||= spec_name.to_s [:source] ||= spec_name.to_s super(spec_name, , &block) end |
Instance Method Details
#find_resource(controller) ⇒ Object
finds the resource from the enclosing resource. Raise CantFindSingleton if there is no enclosing resource
114 115 116 117 |
# File 'lib/resources_controller/specification.rb', line 114 def find_resource(controller) ResourcesController.raise_cant_find_singleton(name, klass) unless controller.enclosing_resource controller.enclosing_resource.send(source) end |
#key ⇒ Object
no key for singleton resources
109 110 111 |
# File 'lib/resources_controller/specification.rb', line 109 def key false end |
#singleton? ⇒ Boolean
returns true
104 105 106 |
# File 'lib/resources_controller/specification.rb', line 104 def singleton? true end |