Class: Orchestrate::Application::Document
- Inherits:
-
Object
- Object
- Orchestrate::Application::Document
- 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
-
#id ⇒ Object
readonly
The
ref
value associated with the document. -
#key_value_pairs ⇒ Object
readonly
The key/value data for this record.
-
#metadata ⇒ Object
readonly
Metadata.
Instance Method Summary collapse
-
#cache ⇒ Object
Returns handle to the SimpleCacheStore singleton instance.
- #cache_enabled? ⇒ Boolean
-
#initialize(key_value_pairs, metadata) ⇒ Document
constructor
Saves the key/value data and Metadata.
-
#save ⇒ Object
Saves the document to cache.
-
#to_event ⇒ Object
Creates a new event instance from the document’s key/value data.
-
#to_rails ⇒ Object
Creates a new model instance, and calls #update_rails.
-
#update_rails(instance) ⇒ Object
Updates the key/value pairs for the model instance with key/value data from the document.
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
#id ⇒ Object (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_pairs ⇒ Object (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 |
#metadata ⇒ Object (readonly)
Metadata.
10 11 12 |
# File 'lib/orchestrate_application/document.rb', line 10 def end |
Instance Method Details
#cache ⇒ Object
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
41 42 43 |
# File 'lib/orchestrate_application/document.rb', line 41 def cache_enabled? cache.is_enabled? end |
#save ⇒ Object
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_event ⇒ Object
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_rails ⇒ Object
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 |