Class: ResourcesController::SingletonSpecification

Inherits:
Specification
  • Object
show all
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

Methods inherited from Specification

#find_custom, #find_from, new

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, options = {}, &block)
  options[:segment] ||= spec_name.to_s
  options[:source]  ||= spec_name.to_s
  
  super(spec_name, options, &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

#keyObject

no key for singleton resources



109
110
111
# File 'lib/resources_controller/specification.rb', line 109

def key
  false
end

#singleton?Boolean

returns true

Returns:

  • (Boolean)


104
105
106
# File 'lib/resources_controller/specification.rb', line 104

def singleton?
  true
end