Module: Dolly::DocumentCreation
Constant Summary
Constants included
from Properties
Properties::SPECIAL_KEYS
Instance Method Summary
collapse
#rails?
Methods included from Properties
#all_property_keys, #properties, #property, #property_clean_doc, #property_keys, #silence_redefinition_of_method
Instance Method Details
#create(attributes) ⇒ Object
31
32
33
|
# File 'lib/dolly/document_creation.rb', line 31
def create(attributes)
new(attributes).tap(&:save)
end
|
#from_doc(doc) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/dolly/document_creation.rb', line 11
def from_doc(doc)
attributes = property_clean_doc(doc)
new(attributes).tap do |model|
doc.each_key do |key|
if model.respond_to?(:"#{key}=")
model.send(:"#{key}=", doc[key])
else
model.send(:doc)[key] = doc[key]
end
end
end
end
|
#from_json(json) ⇒ Object
25
26
27
28
29
|
# File 'lib/dolly/document_creation.rb', line 25
def from_json(json)
raw_data = Oj.load(json, symbol_keys: true)
data = rails? ? data.with_indifferent_access : raw_data
from_doc(data)
end
|