Class: Orchestrate::Application::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestrate_rails/document.rb,
lib/orchestrate_application/document.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_value_pairs, metadata) ⇒ Document

Saves the key/value data and Metadata. Saves the doc to cache when cache is enabled.



20
21
22
23
24
25
26
# File 'lib/orchestrate_application/document.rb', line 20

def initialize(key_value_pairs, )
  @key_value_pairs = key_value_pairs
   = 
  @id = .ref

  save if cache_enabled?
end

Instance Attribute Details

#idObject (readonly)

The ref value associated with the document.



16
17
18
# File 'lib/orchestrate_application/document.rb', line 16

def id
  @id
end

#key_value_pairsObject (readonly)

The key/value data for this record.



13
14
15
# File 'lib/orchestrate_application/document.rb', line 13

def key_value_pairs
  @key_value_pairs
end

#metadataObject (readonly)

Metadata.



10
11
12
# File 'lib/orchestrate_application/document.rb', line 10

def 
  
end

Instance Method Details

#cacheObject

Returns handle to the SimpleCacheStore singleton instance.



37
38
39
# File 'lib/orchestrate_application/document.rb', line 37

def cache
  @@cache ||= SimpleCacheStore.instance
end

#cache_enabled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/orchestrate_application/document.rb', line 41

def cache_enabled?
  cache.is_enabled?
end

#saveObject

Saves the document to cache.



29
30
31
32
33
34
# File '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_eventObject

Creates a new event instance from the document’s key/value data. Defined by Orchestrate::Rails.



27
28
29
# File 'lib/orchestrate_rails/document.rb', line 27

def to_event
  Object.const_get('Orchestrate::Rails::Event').new key_value_pairs
end

#to_railsObject

Creates a new model instance, and calls #update_rails. Defined by Orchestrate::Rails.



21
22
23
# File 'lib/orchestrate_rails/document.rb', line 21

def to_rails
  update_rails Object.const_get(classname).new
end

#update_rails(instance) ⇒ Object

Updates the key/value pairs for the model instance with key/value data from the document. Defined by Orchestrate::Rails.



11
12
13
14
15
16
17
# File '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__", .ref # JMC
  instance
end