Sha256: 1daf679c38e5cf70334f2ea973d26e42f720480a71716d061674fc457b0d5cdd
Contents?: true
Size: 754 Bytes
Versions: 3
Compression:
Stored size: 754 Bytes
Contents
# frozen_string_literal: true require 'dolly/properties' require 'dolly/framework_helper' module Dolly module DocumentCreation include Properties include FrameworkHelper 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 def from_json(json) raw_data = Oj.load(json, symbol_keys: true) data = rails? ? data.with_indifferent_access : raw_data from_doc(data) end def create(attributes) new(attributes).tap(&:save) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dolly-3.1.5 | lib/dolly/document_creation.rb |
dolly-3.1.4 | lib/dolly/document_creation.rb |
dolly-3.1.3 | lib/dolly/document_creation.rb |