Class: Orchestrate::Graph::RelationStem

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(kv_item, type_name) ⇒ RelationStem

Instantiates a new RelationStem

Parameters:

  • kv_item (Orchestrate::KeyValue)

    the KeyValue object this RelationStem acts on behalf of.

  • type_name (#to_s)

    the type of relation this RelationStem interacts with.


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_itemOrchestrate::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

#typeString

the type of relation this RelationStem interacts with.

Returns:

  • (String)

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.

Overloads:

Returns:


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.

Parameters:

  • type_n (#to_s)

    The kind of the relation for the second layer of depth to retreive results for.

Returns:


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

Overloads:

Returns:


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

#eachEnumerator #each {|key_value| ... } ⇒ Object

Retrieves the related items, and iterates over each item in the result. Used as the basis for Enumerable methods.

Overloads:

  • #eachEnumerator

    Returns:

    • (Enumerator)
  • #each {|key_value| ... } ⇒ Object

    Yield Parameters:


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.

Parameters:

  • api_method (Symbol)

    The method on the client to call.

  • args (#to_s, #to_json, Hash)

    The remaining arguments for the specified method.

Returns:


42
43
44
# File 'lib/orchestrate/graph.rb', line 42

def perform(api_method, *args)
  kv_item.perform(api_method, type, *args)
end