Module: DbMod::As

Defined in:
lib/db_mod/as.rb,
lib/db_mod/as/csv.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 Statements::ConfigurableMethod#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

Modules: Csv

Constant Summary collapse

COERCERS =

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

{
  csv: DbMod::As::Csv
}

Class Method Summary collapse

Class Method Details

.extend_method(mod, name, type) ⇒ Object

Extend a method so that the SQL result set it returns will be coerced to the given type. See COERCERS for a list of defined coercion methods.

Parameters:

  • mod (Module)

    module where the method has been defined

  • name (Symbol)

    method name

  • type (Symbol)

    type to which result set should be coerced



30
31
32
33
34
35
36
# File 'lib/db_mod/as.rb', line 30

def self.extend_method(mod, name, type)
  unless COERCERS.key? type
    fail ArgumentError, "#{type} not in #{COERCERS.keys.join ', '}"
  end

  Statements.extend_method(mod, name, COERCERS[type])
end