Sha256: 6420eba731c55b7e42aaa9d1ddb77023299f2851d3073b5d07b5ee74bdbf46e8
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
require_relative 'as/csv' module DbMod # 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 {DbMod::Statements::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) module As # List of available result coercion methods. # Only keys defined here are allowed as arguments # to {DbMod::Statements::ConfigurableMethod#as}. COERCERS = { csv: DbMod::As::Csv } # 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. # # @param mod [Module] module where the method has been defined # @param name [Symbol] method name # @param type [Symbol] type to which result set should be coerced def self.extend_method(mod, name, type) unless COERCERS.key? type fail ArgumentError, "#{type} not in #{COERCERS.keys.join ', '}" end Statements.extend_method(mod, name, COERCERS[type]) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
db_mod-0.0.3 | lib/db_mod/as.rb |