Module: DbMod::Statements::Configuration::As
- Defined in:
- lib/db_mod/statements/configuration/as.rb,
lib/db_mod/statements/configuration/as/csv.rb,
lib/db_mod/statements/configuration/as/json.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 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
Constant Summary collapse
- Configuration =
For extend_method
DbMod::Statements::Configuration
- COERCERS =
List of available result coercion methods. Only keys defined here are allowed as arguments to ConfigurableMethod#as.
{ csv: As::Csv, json: As::Json }
Class Method Summary collapse
-
.extend_method(mod, name, type) ⇒ Object
Extend a method so that the SQL result set it returns will be coerced to the given type.
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.
37 38 39 40 41 42 43 |
# File 'lib/db_mod/statements/configuration/as.rb', line 37 def self.extend_method(mod, name, type) unless COERCERS.key? type fail ArgumentError, "#{type} not in #{COERCERS.keys.join ', '}" end Configuration.process_method_results(mod, name, COERCERS[type]) end |