Class: Abc::BaseConductor

Inherits:
Object
  • Object
show all
Defined in:
lib/abc/base_conductor.rb

Overview

The Base Conductor is the conductor that all other conductors inherit from. Its primary role is to decipher the parameters, retrieve or save data to or from data-facing APIs like a database or a third-party API, and to optionally wrap what it plans to return in an object that provides methods for access (in some cases, abstracting complex logic away from the view).

The Conductor is not responsible, however, for validating or wrapping the data it retrieves. That task is delegated down to the application.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(params, options = {}) ⇒ Hash

Runs the conductor and returns a hash of objects (presenter or otherwise) that are passed to the view.

Parameters:

  • params (HashWithIndifferentAccess)

    The request parameters.

  • options (Hash) (defaults to: {})

    A series of options that override default values.

Returns:

  • (Hash)

    An associative array of presenter objects to be passed to the view.



20
21
22
# File 'lib/abc/base_conductor.rb', line 20

def call(params, options = {})
  new(params, options).to_response
end

Instance Method Details

#to_responseHash

Transforms the data returned by the #data method into an acceptable format to return to the controller. Primarily used to wrap data in presenters, but can pass entities back, too.

Returns:

  • (Hash)

    An associative array of presenter or entity objects to be passed to the view.

Raises:



30
31
32
# File 'lib/abc/base_conductor.rb', line 30

def to_response
  raise ResponseNotSpecifiedError, "#to_response must be overridden when subclassing BaseConductor"
end