module Persistence

Public Class Methods

included(base) click to toggle source
# File lib/bloc_record/persistence.rb, line 5
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

destroy() click to toggle source
# File lib/bloc_record/persistence.rb, line 113
def destroy
  self.class.destroy(self.id)
end
save() click to toggle source
# File lib/bloc_record/persistence.rb, line 101
def save
  self.save! rescue false
end
save!() click to toggle source
# File lib/bloc_record/persistence.rb, line 83
  def save!
    unless self.id
      self.id = self.class.create(BlocRecord::Utility.instance_variables_to_hash(self)).id
      BlocRecord::Utility.reload_obj(self)
      return true
    end

    fields = self.class.attributes.map { |col| "#{col}=#{BlocRecord::Utility.sql_strings(self.instance_variable_get("@#{col}"))}" }.join(",")

    self.class.connection.execute <<-SQL
      UPDATE #{self.class.table}
      SET #{fields}
      WHERE id = #{self.id};
    SQL

    true
  end
update_attribute(attribute, value) click to toggle source
# File lib/bloc_record/persistence.rb, line 105
def update_attribute(attribute, value)
  self.class.update(self.id, { attribute => value })
end
update_attributes(updates) click to toggle source
# File lib/bloc_record/persistence.rb, line 109
def update_attributes(updates)
  self.class.update(self.id, updates)
end