Sha256: 5a82a30520111bb5535a6cc474c7bcf61d437dd6c57d2434b6e51d65762b120a

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module DbMod
  module Statements
    module Configuration
      # 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
      module Returning
        # Extend the given method definition with additional result
        # coercion, if specified using {MethodConfiguration#returning}.
        #
        # @param definition [Proc] base method definition
        # @param config [MethodConfiguration] method configuration
        # @return [Proc] wrapped method definition, or the original
        #   definition if no coercion has been specified
        def self.extend(definition, config)
          return definition unless config.key? :returning

          Configuration.attach_result_processor definition, config[:returning]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
db_mod-0.0.6 lib/db_mod/statements/configuration/returning.rb