Class: Seedy::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/seedy/records/record.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Record

Returns a new instance of Record.



11
12
13
14
15
16
# File 'lib/seedy/records/record.rb', line 11

def initialize(params={})
  define_attribute_methods
  @params = params
  @attributes = {}
  generate_attributes_for(self.columns)
end

Instance Method Details

#inspectObject



28
29
30
# File 'lib/seedy/records/record.rb', line 28

def inspect
  self
end

#to_sObject



32
33
34
35
36
37
38
# File 'lib/seedy/records/record.rb', line 32

def to_s
  attrs = []
  @attributes.keys.each do |k|
    attrs << "#{k}: #{attribute_for_inspect(k)}"
  end
  "#<#{self.class} #{attrs.join(", ")}>"
end

#to_sqlObject



18
19
20
21
22
23
24
25
26
# File 'lib/seedy/records/record.rb', line 18

def to_sql
  sql = <<-EOF
  INSERT INTO #{table_name}
    (#{@attributes.keys.join(",")})
    VALUES
    (#{quote(@attributes.values).join(",")});
  EOF
  sql.gsub!(/^\s{6}/, '')
end