Module: Ribs::Repository::InstanceMethods

Includes:
Ribs::Repository
Defined in:
lib/ribs/repository.rb

Overview

InstanceMethods are those that become available when you the repository for a specific instance. This allows things like saving and destroying a specific instance.

Instance Attribute Summary

Attributes included from Ribs::Repository

#database, #model

Instance Method Summary collapse

Methods included from Ribs::Repository

const_missing, create_repository, ensure_repository

Instance Method Details

#destroy!Object

Removes this instance from the database.



139
140
141
142
143
144
# File 'lib/ribs/repository.rb', line 139

def destroy!
  self.class.destroyed(self.model)
  Ribs.with_handle(self.database) do |h|
    h.delete(self.model)
  end
end

#metadataObject

Get the meta data for this model



134
135
136
# File 'lib/ribs/repository.rb', line 134

def 
  self.class.
end

#saveObject

Saves this instance to the database. If the instance already exists, it will update the database, otherwise it will create it.



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ribs/repository.rb', line 149

def save
  Ribs.with_handle(self.database) do |h|
    if self.class.persistent?(self.model)
      h.update_obj(self.model)
    else
      h.insert_obj(self.model)
      self.class.persistent(self.model)
    end
  end
  self.model
end