module Riagent::Document::ClassMethods
Public Instance Methods
from_json(json_obj, key=nil)
click to toggle source
Returns a Riagent::Document
instance, given a JSON string @param [String] json_object JSON Object string @param [String] key Optional document key. If not provided, will be loaded from _id
attribute in the JSON itself @return [Riagent::Document, nil] Riagent::Document
instance, or nil if the JSON string is nil/empty
# File lib/riagent/document.rb, line 50 def from_json(json_obj, key=nil) return nil if json_obj.nil? or json_obj.empty? attributes_hash = JSON.parse(json_obj) return nil if attributes_hash.empty? instance = self.instantiate(attributes_hash) if key.nil? # Load key from the JSON object key = attributes_hash['_id'] end instance.key = key instance end
instantiate(attributes)
click to toggle source
Returns Riagent::Document
instance, given a Hash of attributes
# File lib/riagent/document.rb, line 64 def instantiate(attributes) self.new attributes end