Sha256: 0b60a9ff5d17761c152813d7a768f0e1194511ad00b040a34eb445902ab5821d
Contents?: true
Size: 966 Bytes
Versions: 4
Compression:
Stored size: 966 Bytes
Contents
module Seedy class Record class_attribute :columns self.columns = {} # Tracks if we have extended our class with attribute methods yet. class_attribute :attribute_methods_generated self.attribute_methods_generated = false def initialize(params={}) define_attribute_methods @params = params @attributes = {} generate_attributes_for(self.columns) end def to_sql sql = <<-EOF INSERT INTO #{table_name} (#{@attributes.keys.join(",")}) VALUES (#{quote(@attributes.values).join(",")}); EOF sql.gsub!(/^\s{6}/, '') end def inspect self end def to_s attrs = [] @attributes.keys.each do |k| attrs << "#{k}: #{attribute_for_inspect(k)}" end "#<#{self.class} #{attrs.join(", ")}>" end Record.class_eval do include Seedy::AttributeMethods end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
seedy-0.6.6 | lib/seedy/records/record.rb |
seedy-0.6.5 | lib/seedy/records/record.rb |
seedy-0.6.4 | lib/seedy/records/record.rb |
seedy-0.6.3 | lib/seedy/records/record.rb |