lib/exegesis/document.rb in mattly-exegesis-0.2.6 vs lib/exegesis/document.rb in mattly-exegesis-0.2.8
- old
+ new
@@ -12,10 +12,22 @@
base.send :include, InstanceMethods
base.send :attr_accessor, :database
end
module ClassMethods
+ def database(db=nil)
+ if db
+ if db.is_a?(Exegesis::Database::Singleton) || db.is_a?(Exegesis::Database)
+ @database = db
+ else
+ raise ArgumentError, "please supply either an Exegesis::Database or Exegesis::Database::Singleton"
+ end
+ else
+ @database
+ end
+ end
+
def timestamps!
define_method :set_timestamps do
@attributes['updated_at'] = Time.now
@attributes['created_at'] ||= Time.now
end
@@ -35,10 +47,10 @@
end
module InstanceMethods
def initialize hash={}, db=nil
super hash
- @database = db
+ @database = db || self.class.database
end
def uri
raise MissingDatabaseError if database.nil?
raise NewDocumentError if rev.nil? || id.nil?
\ No newline at end of file