module Omnidata::Persistence::ClassMethods
Attributes
adapter[R]
Public Instance Methods
build_model(pk, attrs)
click to toggle source
# File lib/omnidata/persistence.rb, line 33 def build_model(pk, attrs) model = new(attrs) model.id = pk model end
count()
click to toggle source
# File lib/omnidata/persistence.rb, line 61 def count adapter.count(table_name) end
create(attrs)
click to toggle source
# File lib/omnidata/persistence.rb, line 46 def create(attrs) key = adapter.create(table_name, attrs) build_model(key, attrs) end
destroy(pk)
click to toggle source
# File lib/omnidata/persistence.rb, line 56 def destroy(pk) adapter.destroy(pk, table_name) self end
find(pk)
click to toggle source
# File lib/omnidata/persistence.rb, line 39 def find(pk) attrs = adapter.find(pk, table_name) if (attrs) build_model(pk, attrs) end end
update(pk, attrs)
click to toggle source
# File lib/omnidata/persistence.rb, line 51 def update(pk, attrs) adapter.update(pk, table_name, attrs) self end
use_database(name)
click to toggle source
# File lib/omnidata/persistence.rb, line 27 def use_database(name) adapter = Adapters::AdapterManager.instance.adapter(name) raise Adapters::AdapterError.new("adapter #{name} does not exist") if adapter.nil? @adapter = adapter end
with_database(name, &block)
click to toggle source
# File lib/omnidata/persistence.rb, line 65 def with_database(name, &block) old = self.adapter.name self.use_database(name) block.call self.use_database(old) end