Module: Cuprum::Rails::Controllers::ClassMethods::Configuration
- Defined in:
- lib/cuprum/rails/controllers/class_methods/configuration.rb
Overview
Provides a DSL for defining controller configuration.
Instance Method Summary collapse
-
#configuration ⇒ Cuprum::Rails::Controllers::Configuration
The configured options for the controller.
- #default_format(format = nil) ⇒ Object
- #own_responders ⇒ Object
-
#repository ⇒ Cuprum::Collections::Repository
Returns the repository defined for the controller.
-
#resource ⇒ Cuprum::Rails::Resource
Returns the resource defined for the controller.
-
#responder(format, responder_class) ⇒ Object
Assigns a responder class to handle requests of the specified format.
-
#responders ⇒ Hash<Symbol, Class>
The responder classes defined for the controller, by format.
-
#serializers ⇒ Hash<Class, Object>, Hash<Symbol, Hash<Class, Object>>
The serializers for converting result values into serialized data.
Instance Method Details
#configuration ⇒ Cuprum::Rails::Controllers::Configuration
Returns the configured options for the controller.
12 13 14 |
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 12 def configuration Cuprum::Rails::Controllers::Configuration.new(self) end |
#default_format ⇒ Symbol #default_format(format) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 23 def default_format(format = nil) if format.nil? return @default_format if @default_format return superclass.default_format if controller_class?(superclass) return nil end validate_name(format, as: 'format') @default_format = format.intern end |
#own_responders ⇒ Object
38 39 40 |
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 38 def own_responders @own_responders ||= {} end |
#repository ⇒ Cuprum::Collections::Repository
Returns the repository defined for the controller.
46 47 48 |
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 46 def repository nil end |
#resource ⇒ Cuprum::Rails::Resource
Returns the resource defined for the controller.
Controller subclasses must override this method.
59 60 61 62 |
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 59 def resource raise Cuprum::Rails::Controller::UndefinedResourceError, "no resource defined for #{name}" end |
#responder(format, responder_class) ⇒ Object
Assigns a responder class to handle requests of the specified format.
68 69 70 71 72 73 |
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 68 def responder(format, responder_class) validate_name(format, as: 'format') validate_class(responder_class, as: 'responder') own_responders[format.intern] = responder_class end |
#responders ⇒ Hash<Symbol, Class>
Returns the responder classes defined for the controller, by format.
77 78 79 80 81 82 83 |
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 77 def responders ancestors .select { |ancestor| ancestor.respond_to?(:own_responders) } .reverse_each .map(&:own_responders) .reduce(&:merge) end |
#serializers ⇒ Hash<Class, Object>, Hash<Symbol, Hash<Class, Object>>
Returns the serializers for converting result values into serialized data.
87 88 89 90 91 |
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 87 def serializers { json: Cuprum::Rails::Serializers::Json.default_serializers } end |