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

id[R]

The ref value associated with the document.

key_value_pairs[R]

The key/value data for this record.

metadata[R]

Public Class Methods

new(key_value_pairs, metadata) click to toggle source

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

cache() click to toggle source

Returns handle to the SimpleCacheStore singleton instance.

# File rails/lib/orchestrate_application/document.rb, line 37
def cache
  @@cache ||= SimpleCacheStore.instance
end
cache_enabled?() click to toggle source
# File rails/lib/orchestrate_application/document.rb, line 41
def cache_enabled?
  cache.is_enabled?
end
save() click to toggle source

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
to_event() click to toggle source

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
to_rails() click to toggle source

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
update_rails(instance) click to toggle source

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

classname() click to toggle source
# 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