Module: DbMod::Statements::Configuration::As

Defined in:
lib/db_mod/statements/configuration/as.rb,
lib/db_mod/statements/configuration/as/csv.rb,
lib/db_mod/statements/configuration/as/json.rb

Overview

Contains coercers and other functions that allow module instance methods returning an SQL result set to be extended with additional result coercion and formatting. The normal way to access this functionality is via MethodConfiguration#as, which is available when defining a statement method or prepared method:

def_statement(:a, 'SELECT a, b, c FROM foo').as(:csv)
def_prepared(:b, 'SELECT d, e, f FROM bar').as(:csv)

Defined Under Namespace

Classes: Csv, Json

Constant Summary collapse

COERCERS =

List of available result coercion methods. Only keys defined here are allowed as arguments to ConfigurableMethod#as.

{
  csv: As::Csv,
  json: As::Json
}

Class Method Summary collapse

Class Method Details

.extend(definition, config) ⇒ Proc

Extend the given method definition with additional result coercion, if specified using MethodConfiguration#as.

Parameters:

  • definition (Proc)

    base method definition

  • config (MethodConfiguration)

    method configuration

Returns:

  • (Proc)

    wrapped method definition, or the original definition if no coercion has been specified



33
34
35
36
37
38
# File 'lib/db_mod/statements/configuration/as.rb', line 33

def self.extend(definition, config)
  type = config[:as]
  return definition if type.nil?

  Configuration.attach_result_processor definition, COERCERS[type]
end