Module: DbMod::Statements::Configuration

Defined in:
lib/db_mod/statements/configuration.rb,
lib/db_mod/statements/configuration/as.rb,
lib/db_mod/statements/configuration/as/csv.rb,
lib/db_mod/statements/configuration/single.rb,
lib/db_mod/statements/configuration/as/json.rb,
lib/db_mod/statements/configuration/single/row.rb,
lib/db_mod/statements/configuration/single/value.rb,
lib/db_mod/statements/configuration/single/column.rb,
lib/db_mod/statements/configuration/configurable_method.rb,
lib/db_mod/statements/configuration/single/required_row.rb,
lib/db_mod/statements/configuration/single/required_value.rb

Overview

Provides additional functionality to statement and prepared methods, allowing additional processing of arguments and results using the dsl extensions exposed via ConfigurableMethod.

Defined Under Namespace

Modules: As, Single Classes: ConfigurableMethod

Class Method Summary collapse

Class Method Details

.def_configurable(mod, name, definition) ⇒ DbMod::Statements::ConfigurableMethod

Used by submodules to when defining a method as declared by def_statement or def_prepared. Wraps the defined method so that it may be extended with additional argument and result processing.

Parameters:

  • mod (Module)

    the module where the method has been declared

  • name (Symbol)

    the name of the module that has been defined

  • definition (Proc)

    method definition

Returns:

  • (DbMod::Statements::ConfigurableMethod)

    dsl object for further extending the method



18
19
20
21
22
# File 'lib/db_mod/statements/configuration.rb', line 18

def self.def_configurable(mod, name, definition)
  mod.instance_eval { define_method(name, definition) }

  ConfigurableMethod.new(mod, name)
end

.process_method_results(mod, name, wrapper) ⇒ Object

Used by ConfigurableMethod (and associated code) to wrap a defined statement method or prepared method with additional result processing. A method should be provided, which accepts an SQL result set and returns some transformation of the results. The original method declaration will be replaced, so that the original method definition is called and the results are passed through this given method.

Parameters:

  • mod (Module)

    the module where the method has been defined

  • name (Symbol)

    the method name

  • wrapper (#call)

    a function that processes the SQL results in some way



35
36
37
38
39
40
41
42
43
# File 'lib/db_mod/statements/configuration.rb', line 35

def self.process_method_results(mod, name, wrapper)
  mod.instance_eval do
    wrapped = instance_method(name)

    define_method(name, lambda do |*args|
      wrapper.call wrapped.bind(self).call(*args)
    end)
  end
end