Module: Relaxo::Model::Document::ClassMethods

Defined in:
lib/relaxo/model/document.rb

Instance Method Summary collapse

Instance Method Details

#create(database, properties = nil) ⇒ Object

Create a new document with a particular specified type.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/relaxo/model/document.rb', line 49

def create(database, properties = nil)
	instance = self.new(database, {TYPE => @type})

	if properties
		properties.each do |key, value|
			instance[key] = value
		end
	end

	instance.after_create

	return instance
end

#fetch(database, id_or_attributes) ⇒ Object

Fetch a record or create a model object from a hash of attributes.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/relaxo/model/document.rb', line 64

def fetch(database, id_or_attributes)
	if Hash === id_or_attributes
		instance = self.new(database, id_or_attributes)
	else
		instance = self.new(database, database.get(id_or_attributes).to_hash)
	end

	instance.after_fetch

	return instance
end