Module: SnFoil::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/snfoil/controller.rb,
lib/snfoil/controller/version.rb
Overview
ActiveSupport::Concern for Controller functionality A SnFoil::Controller is essentially a context but instead of using #action uses a more simplified workflow called #endpoint. The method or block passed to endpoint is ultimately what renders. #endpoint creates the following intervals:
-
setup_*
-
process_*
This concern also adds the following class methods
-
context - The context associated with the controller to process the business logic
-
deserializer - the deserializer associated with the controller to allow list incoming params
-
endpoint - helper function to build endpoint methods
-
serializer - The serializer associated to render the context’s output
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
'1.1.3'
Instance Method Summary collapse
- #deserialize(params, **options) ⇒ Object
- #run_context(method = nil, **options) ⇒ Object
- #serialize(object, **options) ⇒ Object
Instance Method Details
#deserialize(params, **options) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/snfoil/controller.rb', line 99 def deserialize(params, **) deserializer = .fetch(:deserializer) { self.class.snfoil_deserializer } return params unless deserializer exec_deserialize(deserializer, params, **) end |
#run_context(method = nil, **options) ⇒ Object
106 107 108 109 110 |
# File 'lib/snfoil/controller.rb', line 106 def run_context(method = nil, **) ([:context] || self.class.snfoil_context) .new(entity: entity) .send(method || [:context_action] || [:controller_action], **) end |
#serialize(object, **options) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/snfoil/controller.rb', line 92 def serialize(object, **) serializer = .fetch(:serializer) { self.class.snfoil_serializer } return object unless serializer exec_serialize(serializer, object, **) end |