Class: Orchestrate::Graph::RelationStem
- Inherits:
-
Object
- Object
- Orchestrate::Graph::RelationStem
- Includes:
- Enumerable
- Defined in:
- lib/orchestrate/graph.rb
Overview
A directed relationship against a single KeyValue object.
Defined Under Namespace
Classes: Traversal
Instance Attribute Summary collapse
-
#kv_item ⇒ Orchestrate::KeyValue
the KeyValue object this RelationStem acts on behalf of.
-
#type ⇒ String
the type of relation this RelationStem interacts with.
Instance Method Summary collapse
- #<<(other_item_or_collection_name, other_key = nil) ⇒ Orchestrate::API::Response (also: #push)
-
#[](type_n) ⇒ Traversal
Adds depth to the retrieval of related items.
- #delete(other_item_or_collection_name, other_key = nil) ⇒ Orchestrate::API::Response
-
#each(&block) ⇒ Object
Retrieves the related items, and iterates over each item in the result.
-
#initialize(kv_item, type_name) ⇒ RelationStem
constructor
Instantiates a new RelationStem.
-
#perform(api_method, *args) ⇒ API::Response
Calls a method on the KeyValue's Collection's API Client, providing the relation type.
Constructor Details
#initialize(kv_item, type_name) ⇒ RelationStem
Instantiates a new RelationStem
33 34 35 36 |
# File 'lib/orchestrate/graph.rb', line 33 def initialize(kv_item, type_name) @kv_item = kv_item @type = type_name.to_s end |
Instance Attribute Details
#kv_item ⇒ Orchestrate::KeyValue
the KeyValue object this RelationStem acts on behalf of.
24 25 26 |
# File 'lib/orchestrate/graph.rb', line 24 def kv_item @kv_item end |
#type ⇒ String
the type of relation this RelationStem interacts with.
28 29 30 |
# File 'lib/orchestrate/graph.rb', line 28 def type @type end |
Instance Method Details
#<<(key_value_item) ⇒ Orchestrate::API::Response #<<(collection_name, key_name) ⇒ Orchestrate::API::Response Also known as: push
Creates a relationship between two objects. Relations can span collections.
54 55 56 57 58 |
# File 'lib/orchestrate/graph.rb', line 54 def <<(other_item_or_collection_name, other_key=nil) coll, key = get_collection_and_key(kv_item, nil) other_collection, other_key = get_collection_and_key(other_item_or_collection_name, other_key) perform(:put_relation, other_collection, other_key) end |
#[](type_n) ⇒ Traversal
Adds depth to the retrieval of related items.
77 78 79 |
# File 'lib/orchestrate/graph.rb', line 77 def [](type_n) Traversal.new(kv_item, [type, type_n.to_s]) end |
#delete(key_value_item) ⇒ Orchestrate::API::Response #delete(collection_name, key_name) ⇒ Orchestrate::API::Response
68 69 70 71 72 |
# File 'lib/orchestrate/graph.rb', line 68 def delete(other_item_or_collection_name, other_key=nil) coll, key = get_collection_and_key(kv_item, nil) other_collection, other_key = get_collection_and_key(other_item_or_collection_name, other_key) perform(:delete_relation, other_collection, other_key) end |
#each ⇒ Enumerator #each {|key_value| ... } ⇒ Object
Retrieves the related items, and iterates over each item in the result. Used as the basis for Enumerable methods.
90 91 92 |
# File 'lib/orchestrate/graph.rb', line 90 def each(&block) Traversal.new(kv_item, [type]).each(&block) end |
#perform(api_method, *args) ⇒ API::Response
Calls a method on the KeyValue's Collection's API Client, providing the relation type.
42 43 44 |
# File 'lib/orchestrate/graph.rb', line 42 def perform(api_method, *args) kv_item.perform(api_method, type, *args) end |