module Cuprum::Rails::Controllers::ClassMethods::Configuration
Provides a DSL for defining controller configuration.
Public Instance Methods
configuration()
click to toggle source
@return [Cuprum::Rails::Controllers::Configuration] the configured options
for the controller.
# File lib/cuprum/rails/controllers/class_methods/configuration.rb, line 12 def configuration Cuprum::Rails::Controllers::Configuration.new(self) end
own_responders()
click to toggle source
@private
# File lib/cuprum/rails/controllers/class_methods/configuration.rb, line 17 def own_responders @own_responders ||= {} end
resource()
click to toggle source
Returns the resource defined for the controller.
Controller
subclasses must override this method.
@return [Cuprum::Rails::Resource] the resource defined for the
controller.
@raise [Cuprum::Rails::Controller::UndefinedResourceError] if the
controller does not define a resource.
# File lib/cuprum/rails/controllers/class_methods/configuration.rb, line 30 def resource raise Cuprum::Rails::Controller::UndefinedResourceError, "no resource defined for #{name}" end
responder(format, responder_class)
click to toggle source
Assigns a responder class to handle requests of the specified format.
@param format [String, Symbol] The request format to handle. @param responder_class [Class] The class of responder.
# File lib/cuprum/rails/controllers/class_methods/configuration.rb, line 39 def responder(format, responder_class) validate_name(format, as: 'format') validate_class(responder_class, as: 'responder') own_responders[format.intern] = responder_class end
responders()
click to toggle source
@return [Hash<Symbol, Class>] the responder classes defined for the
controller, by format.
# File lib/cuprum/rails/controllers/class_methods/configuration.rb, line 48 def responders ancestors .select { |ancestor| ancestor.respond_to?(:own_responders) } .reverse_each .map(&:own_responders) .reduce(&:merge) end
serializers()
click to toggle source
@return [Hash<Class, Object>, Hash<Symbol, Hash<Class, Object>>] the
serializers for converting result values into serialized data.
# File lib/cuprum/rails/controllers/class_methods/configuration.rb, line 58 def serializers { json: Cuprum::Rails::Serializers::Json.default_serializers } end