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

Author:

  • Matthew Howes

Since:

  • 0.1.0

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =

Since:

  • 0.1.0

'1.1.3'

Instance Method Summary collapse

Instance Method Details

#deserialize(params, **options) ⇒ Object

Since:

  • 0.1.0



99
100
101
102
103
104
# File 'lib/snfoil/controller.rb', line 99

def deserialize(params, **options)
  deserializer = options.fetch(:deserializer) { self.class.snfoil_deserializer }
  return params unless deserializer

  exec_deserialize(deserializer, params, **options)
end

#run_context(method = nil, **options) ⇒ Object

Since:

  • 0.1.0



106
107
108
109
110
# File 'lib/snfoil/controller.rb', line 106

def run_context(method = nil, **options)
  (options[:context] || self.class.snfoil_context)
    .new(entity: entity)
    .send(method || options[:context_action] || options[:controller_action], **options)
end

#serialize(object, **options) ⇒ Object

Since:

  • 0.1.0



92
93
94
95
96
97
# File 'lib/snfoil/controller.rb', line 92

def serialize(object, **options)
  serializer = options.fetch(:serializer) { self.class.snfoil_serializer }
  return object unless serializer

  exec_serialize(serializer, object, **options)
end