lib/exegesis/document.rb in mattly-exegesis-0.0.7 vs lib/exegesis/document.rb in mattly-exegesis-0.0.8
- old
+ new
@@ -72,11 +72,14 @@
end
alias :_rev :rev
alias_method :document_save, :save
+ attr_accessor :parent
+
def save
+ raise ChildError, "cannot save if a parent is set" if parent
set_timestamps if respond_to?(:set_timestamps)
if respond_to?(:set_unique_id) && id.nil?
@unique_id_attempt = 0
begin
self['_id'] = set_unique_id
@@ -127,18 +130,19 @@
Exegesis.document_classes[nil] # whatever the default is? Hell idk.
end
with = klass == Time ? :parse : :new
casted = klass.send with, value
+ casted.parent = self if casted.respond_to?(:parent)
casted
end
def load_reference ids
- raise ArgumentError, "a database is required for loading a reference" unless database
+ raise ArgumentError, "a database is required for loading a reference" unless database || (parent && parent.database)
if ids.is_a?(Array)
- ids.map {|val| Exegesis::Document.instantiate(database.get(val)) }
+ ids.map {|val| Exegesis::Document.instantiate((database || parent && parent.database).get(val)) }
else
- Exegesis::Document.instantiate(database.get(ids))
+ Exegesis::Document.instantiate((database || parent && parent.database).get(ids))
end
end
end
end
\ No newline at end of file