module Relaxo::Model::Document
Public Class Methods
included(child)
click to toggle source
# File lib/relaxo/model/document.rb, line 50 def self.included(child) child.send(:include, Component) child.send(:extend, ClassMethods) end
Public Instance Methods
<=>(other)
click to toggle source
Equality is done only on id to improve performance.
# File lib/relaxo/model/document.rb, line 223 def <=> other self.id <=> other.id if other end
==(other)
click to toggle source
# File lib/relaxo/model/document.rb, line 231 def == other self.attributes == other.attributes if other end
after_create()
click to toggle source
Set any default values:
# File lib/relaxo/model/document.rb, line 219 def after_create end
after_delete()
click to toggle source
# File lib/relaxo/model/document.rb, line 199 def after_delete end
after_fetch()
click to toggle source
# File lib/relaxo/model/document.rb, line 214 def after_fetch raise TypeError.new(self) unless valid_type? end
after_save()
click to toggle source
# File lib/relaxo/model/document.rb, line 115 def after_save end
before_delete()
click to toggle source
# File lib/relaxo/model/document.rb, line 196 def before_delete end
before_save(changeset)
click to toggle source
Update any calculations:
# File lib/relaxo/model/document.rb, line 112 def before_save(changeset) end
delete(changeset)
click to toggle source
# File lib/relaxo/model/document.rb, line 202 def delete(changeset) before_delete @changed.clear paths.each do |path| changeset.delete(path) end after_delete end
dup(dataset = @dataset)
click to toggle source
Make a copy of the record, as if calling create.
# File lib/relaxo/model/document.rb, line 132 def dup(dataset = @dataset) # Splat already calls dup internally I guess. clone = self.class.new(dataset, nil, @changed.dup, **@attributes) clone.after_create return clone end
empty?()
click to toggle source
# File lib/relaxo/model/document.rb, line 239 def empty? @attributes.empty? end
eql?(other)
click to toggle source
# File lib/relaxo/model/document.rb, line 227 def eql? other self.id.eql?(other.id) if other end
hash()
click to toggle source
# File lib/relaxo/model/document.rb, line 235 def hash self.id.hash end
inspect()
click to toggle source
# File lib/relaxo/model/document.rb, line 127 def inspect "\#<#{self.class}:#{self.id} #{self.attributes.inspect}>" end
new_record?()
click to toggle source
# File lib/relaxo/model/document.rb, line 95 def new_record? !persisted? end
paths() { |object_path(self, **attributes)| ... }
click to toggle source
# File lib/relaxo/model/document.rb, line 141 def paths return to_enum(:paths) unless block_given? self.class.keys.each do |name, key| # @attributes is not modified until we call self.dump (which flattens @attributes into @changes). When we generate paths, we want to ensure these are done based on the non-mutable state of the object. yield key.object_path(self, **@attributes) end end
persisted?()
click to toggle source
# File lib/relaxo/model/document.rb, line 99 def persisted? @object != nil end
save(changeset)
click to toggle source
Save the model object.
# File lib/relaxo/model/document.rb, line 151 def save(changeset) before_save(changeset) return if persisted? and @changed.empty? if errors = self.validate(changeset) return errors end existing_paths = persisted? ? paths.to_a : [] # Write data, check if any actual changes made: object = changeset.append(self.dump) return if object == @object existing_paths.each do |path| changeset.delete(path) end paths do |path| if changeset.exist?(path) raise KeyError, "Dataset already contains path: #{path}, when inserting #{@attributes.inspect}" end changeset.write(path, object) end @dataset = changeset @object = object after_save return true end
save!(changeset)
click to toggle source
# File lib/relaxo/model/document.rb, line 186 def save!(changeset) result = self.save(changeset) if result != true raise ValidationFailure.new(self, result) end return self end
to_s()
click to toggle source
The canonical path to the object in the data store, assuming there is some unique way to identify the object.
Calls superclass method
# File lib/relaxo/model/document.rb, line 119 def to_s if primary_key = self.class.primary_key primary_key.object_path(self) else super end end
type()
click to toggle source
# File lib/relaxo/model/document.rb, line 103 def type @attributes[:type] end
valid_type?()
click to toggle source
# File lib/relaxo/model/document.rb, line 107 def valid_type? self.type == self.class.type end