class SQLExporter::Exporter_generic
The exporter class of a 'generic' sql dialect. This should be the parent for all dialect-specific exporter classes.
Attributes
separator[R]
Public Class Methods
new( tidy )
click to toggle source
Class constructor.
# File lib/sqlexporter.rb, line 53 def initialize ( tidy ) @tidy = tidy @separator = @tidy ? "\n" : " " end
Public Instance Methods
export( obj )
click to toggle source
exports a string with a query from object. this method should be called from a child class with defined constant arrays [select|delete|update|insert]_syntax. methods defined in the array are called in the specified order for the object obj.
# File lib/sqlexporter.rb, line 64 def export ( obj ) rules_const_name = obj.class.name.sub( /^.+?::Basic([^_]+).+/, '\1' ).upcase + "_SYNTAX" begin rules = self.class.const_get( rules_const_name.to_sym ) rescue NameError raise NameError, ERR_INVALID_RULES + " '" + self.send( :dialect ) + "'" end string = "" rules.each do |rule| if rule.is_a? String string += rule + @separator elsif rule.is_a? Symbol res = self.send( rule, obj ).to_s string += res string += @separator if ! res.empty? end end return string end
gen_joins( obj )
click to toggle source
Generic representation of the JOIN clause
# File lib/sqlexporter.rb, line 87 def gen_joins ( obj ) arr_joins = [ ] if obj.gen_joins arr_joins = obj.gen_joins.map { |join| join.to_s } end return arr_joins.join( @separator ) end
method_missing( method, *args )
click to toggle source
Construct an expression string for an object's attribute defined in in the METHODS constant array.
# File lib/sqlexporter.rb, line 99 def method_missing ( method, *args ) obj = args[0] return '' if ! obj.is_a? SQLObject result = "" _attr = obj.send method if _attr.is_a? Array result += _attr.join @separator elsif _attr result += _attr.to_s end return result end