Module: DbMod::Statements::Configuration::Returning

Defined in:
lib/db_mod/statements/configuration/returning.rb

Overview

Provides functionality backing the MethodConfiguration#returning setting. Allows a block to be declared that may perform additional processing on the SQL result set (the result of whatever other result transformations have been specified using MethodConfiguration#as or MethodConfiguration#single), and which may transform or replace entirely the method return value.

def_statement(:csv_email, 'SELECT * FROM foo') do
  as(:csv)
  returning { |csv| build_email(csv) }
end

Class Method Summary collapse

Class Method Details

.extend(definition, config) ⇒ Proc

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

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



23
24
25
26
27
# File 'lib/db_mod/statements/configuration/returning.rb', line 23

def self.extend(definition, config)
  return definition unless config.key? :returning

  Configuration.attach_result_processor definition, config[:returning]
end