module Relaxo::Model::Document::ClassMethods

Public Instance Methods

create(dataset, properties = nil) click to toggle source

Create a new document with a particular specified type.

# File lib/relaxo/model/document.rb, line 57
def create(dataset, properties = nil)
        instance = self.new(dataset, type: @type)

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

        instance.after_create

        return instance
end
fetch(dataset, path = nil, **attributes) click to toggle source

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

# File lib/relaxo/model/document.rb, line 80
def fetch(dataset, path = nil, **attributes)
        if path and object = dataset.read(path)
                instance = self.new(dataset, object, **attributes)
                
                instance.load_object
                
                instance.after_fetch
                
                return instance
        end
end
insert(dataset, properties) click to toggle source
# File lib/relaxo/model/document.rb, line 71
def insert(dataset, properties)
        instance = self.create(dataset, properties)
        
        instance.save(dataset)
        
        return instance
end