Module: Relaxo::Model::Document::ClassMethods
- Defined in:
- lib/relaxo/model/document.rb
Instance Method Summary collapse
-
#create(dataset, properties = nil) ⇒ Object
Create a new document with a particular specified type.
-
#fetch(dataset, path = nil, **attributes) ⇒ Object
Fetch a record or create a model object from a hash of attributes.
- #insert(dataset, properties) ⇒ Object
Instance Method Details
#create(dataset, properties = nil) ⇒ Object
Create a new document with a particular specified type.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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) ⇒ Object
Fetch a record or create a model object from a hash of attributes.
80 81 82 83 84 85 86 87 88 89 90 |
# 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) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/relaxo/model/document.rb', line 71 def insert(dataset, properties) instance = self.create(dataset, properties) instance.save(dataset) return instance end |