class Orchestrate::Application::Document
Object to encapsulate the key/value data along with the metadata associated with an Orchestrate.io record. Used to return results from the application layer.
Extensions update_rails, to_rails, to_event are defined in the Orchestrate::Rails module and are accessible within that namespace.
Attributes
The ref
value associated with the document.
The key/value data for this record.
Public Class Methods
Saves the key/value data and Metadata. Saves the doc to cache when cache is enabled.
# File rails/lib/orchestrate_application/document.rb, line 20 def initialize(key_value_pairs, metadata) @key_value_pairs = key_value_pairs @metadata = metadata @id = @metadata.ref save if cache_enabled? end
Public Instance Methods
Returns handle to the SimpleCacheStore singleton instance.
# File rails/lib/orchestrate_application/document.rb, line 37 def cache @@cache ||= SimpleCacheStore.instance end
# File rails/lib/orchestrate_application/document.rb, line 41 def cache_enabled? cache.is_enabled? end
Saves the document to cache.
# File rails/lib/orchestrate_application/document.rb, line 29 def save # puts "DOC: saving -> '#{cache}'" # puts " respond_to? :save -> '#{cache.respond_to? :save}'" cache.save self # puts "DOC: saved" end
Creates a new event instance from the document's key/value data. Defined by Orchestrate::Rails.
# File rails/lib/orchestrate_rails/document.rb, line 27 def to_event Object.const_get('Orchestrate::Rails::Event').new key_value_pairs end
Creates a new model instance, and calls update_rails. Defined by Orchestrate::Rails.
# File rails/lib/orchestrate_rails/document.rb, line 21 def to_rails update_rails Object.const_get(classname).new end
Updates the key/value pairs for the model instance with key/value data from the document. Defined by Orchestrate::Rails.
# File rails/lib/orchestrate_rails/document.rb, line 11 def update_rails(instance) key_value_pairs.each { |k,v| instance.instance_variable_set "@#{k.to_orchio_rails_attr}", v } instance.instance_variable_set "@__ref_value__", metadata.ref # JMC instance end
Private Instance Methods
# File rails/lib/orchestrate_rails/document.rb, line 32 def classname Orchestrate::Rails::Schema.instance.fullclassname metadata.collection # Orchestrate::Rails::Schema.instance.classname(metadata.collection) JMC end