Class: DbMod::Statements::ConfigurableMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/db_mod/statements/configurable_method.rb

Overview

Encapsulates a method that has just been defined via the dsl exposed in DbMod::Statements so that it can be extended with additional processing such as result coercion.

The pattern here is something similar to rack’s middleware. Calling any of the extension methods below will replace the original method defined by def_prepared or def_statement with a wrapper function that may perform processing on given arguments, pass them to the original function, then perform additional processing on the result.

Instance Method Summary collapse

Constructor Details

#initialize(mod, name) ⇒ ConfigurableMethod

Encapsulate a method that has been newly defined by a DbMod dsl function, for additional configuration.

Parameters:

  • mod (Module)

    the DbMod enabled module where the method was defined

  • name (Symbol)

    the method name



23
24
25
26
# File 'lib/db_mod/statements/configurable_method.rb', line 23

def initialize(mod, name)
  @mod = mod
  @name = name
end

Instance Method Details

#as(type) ⇒ self

Extend the method by converting results into a given format, using one of the coercion methods defined under As.

Parameters:

  • type (Symbol)

    for now, only :csv is accepted

Returns:

  • (self)


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

def as(type)
  DbMod::As.extend_method(@mod, @name, type)

  self
end