Class: Cuprum::Rails::Controllers::Configuration
- Inherits:
-
Object
- Object
- Cuprum::Rails::Controllers::Configuration
- Extended by:
- Forwardable
- Defined in:
- lib/cuprum/rails/controllers/configuration.rb
Overview
Data object that stores a controller’s configuration.
Instance Attribute Summary collapse
-
#controller ⇒ #resource, #responders
readonly
The controller to delegate configuration.
Instance Method Summary collapse
-
#controller_name ⇒ String
The name of the controller.
-
#default_format ⇒ Symbol
The default format for controller requests.
-
#initialize(controller) ⇒ Configuration
constructor
A new instance of Configuration.
-
#middleware ⇒ Array<Cuprum::Rails::Controllers::Middleware>
The middleware defined for the controller.
-
#middleware_for(action_name) ⇒ Array<Cuprum::Rails::Controllers::Middleware>
Finds the configured middleware for the requested action name.
-
#repository ⇒ Cuprum::Collections::Repository
The repository containing the data collections for the application or scope.
-
#resource ⇒ Cuprum::Rails::Resource
The resource defined for the controller.
-
#responder_for(format) ⇒ Class
Finds the configured responder for the requested 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.
-
#serializers_for(format) ⇒ Hash<Class, Object>
Finds the configured serializers for the requested format.
Constructor Details
#initialize(controller) ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 |
# File 'lib/cuprum/rails/controllers/configuration.rb', line 14 def initialize(controller) @controller = controller end |
Instance Attribute Details
#controller ⇒ #resource, #responders (readonly)
Returns the controller to delegate configuration.
19 20 21 |
# File 'lib/cuprum/rails/controllers/configuration.rb', line 19 def controller @controller end |
Instance Method Details
#controller_name ⇒ String
Returns the name of the controller.
|
# File 'lib/cuprum/rails/controllers/configuration.rb', line 21
|
#default_format ⇒ Symbol
Returns the default format for controller requests.
|
# File 'lib/cuprum/rails/controllers/configuration.rb', line 24
|
#middleware ⇒ Array<Cuprum::Rails::Controllers::Middleware>
Returns the middleware defined for the controller.
|
# File 'lib/cuprum/rails/controllers/configuration.rb', line 27
|
#middleware_for(action_name) ⇒ Array<Cuprum::Rails::Controllers::Middleware>
Finds the configured middleware for the requested action name.
62 63 64 |
# File 'lib/cuprum/rails/controllers/configuration.rb', line 62 def middleware_for(action_name) middleware.select { |item| item.matches?(action_name) } end |
#repository ⇒ Cuprum::Collections::Repository
Returns the repository containing the data collections for the application or scope.
|
# File 'lib/cuprum/rails/controllers/configuration.rb', line 31
|
#resource ⇒ Cuprum::Rails::Resource
Returns the resource defined for the controller.
|
# File 'lib/cuprum/rails/controllers/configuration.rb', line 35
|
#responder_for(format) ⇒ Class
Finds the configured responder for the requested format.
74 75 76 77 78 79 |
# File 'lib/cuprum/rails/controllers/configuration.rb', line 74 def responder_for(format) responders.fetch(format) do raise Cuprum::Rails::Controller::UnknownFormatError, "no responder registered for format #{format.inspect}" end end |
#responders ⇒ Hash<Symbol, Class>
Returns the responder classes defined for the controller, by format.
|
# File 'lib/cuprum/rails/controllers/configuration.rb', line 39
|
#serializers ⇒ Hash<Class, Object>, Hash<Symbol, Hash<Class, Object>>
Returns the serializers for converting result values into serialized data.
47 48 49 50 51 52 53 54 |
# File 'lib/cuprum/rails/controllers/configuration.rb', line 47 def_delegators :@controller, :controller_name, :default_format, :middleware, :repository, :resource, :responders, :serializers |
#serializers_for(format) ⇒ Hash<Class, Object>
Finds the configured serializers for the requested format.
87 88 89 90 91 |
# File 'lib/cuprum/rails/controllers/configuration.rb', line 87 def serializers_for(format) serializers .select { |key, _| key.is_a?(Class) } .merge(serializers.fetch(format, {})) end |