Module: Relaxo::Model::Document

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

TYPE =
'type'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(child) ⇒ Object



42
43
44
45
# File 'lib/relaxo/model/document.rb', line 42

def self.included(child)
	child.send(:include, Component)
	child.send(:extend, ClassMethods)
end

Instance Method Details

#<=>(other) ⇒ Object

Equality is done only on id



149
150
151
# File 'lib/relaxo/model/document.rb', line 149

def <=> other
	self.id <=> other.id
end

#after_createObject

Set any default values:



145
146
# File 'lib/relaxo/model/document.rb', line 145

def after_create
end

#after_deleteObject



130
131
# File 'lib/relaxo/model/document.rb', line 130

def after_delete
end

#after_fetchObject



141
142
# File 'lib/relaxo/model/document.rb', line 141

def after_fetch
end

#after_saveObject



103
104
# File 'lib/relaxo/model/document.rb', line 103

def after_save
end

#before_deleteObject



127
128
# File 'lib/relaxo/model/document.rb', line 127

def before_delete
end

#before_saveObject

Update any calculations:



100
101
# File 'lib/relaxo/model/document.rb', line 100

def before_save
end

#changed?(key) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/relaxo/model/document.rb', line 87

def changed? key
	@changed.include? key.to_s
end

#deleteObject



133
134
135
136
137
138
139
# File 'lib/relaxo/model/document.rb', line 133

def delete
	before_delete

	@database.delete(@attributes)

	after_delete
end

#dup(database = @database) ⇒ Object

Duplicate the model object, and possibly change the database it is connected to. You will potentially have two objects referring to the same record.



107
108
109
110
111
112
113
# File 'lib/relaxo/model/document.rb', line 107

def dup(database = @database)
	clone = self.class.new(database, @attributes.dup)
	
	clone.after_fetch
	
	return clone
end

#idObject



79
80
81
# File 'lib/relaxo/model/document.rb', line 79

def id
	@attributes[ID]
end

#revObject



91
92
93
# File 'lib/relaxo/model/document.rb', line 91

def rev
	@attributes[REV]
end

#saveObject

Save the model object, raises ‘ValidationErrors` if there are validation errors.

Raises:



116
117
118
119
120
121
122
123
124
125
# File 'lib/relaxo/model/document.rb', line 116

def save
	before_save

	errors = self.flatten!
	raise ValidationErrors.new(errors) if errors.size > 0

	@database.save(@attributes)

	after_save
end

#saved?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/relaxo/model/document.rb', line 83

def saved?
	@attributes.key? ID
end

#typeObject



95
96
97
# File 'lib/relaxo/model/document.rb', line 95

def type
	@attributes[TYPE]
end