class Orchestrate::Graph::RelationStem

A directed relationship against a single KeyValue object.

Attributes

kv_item[RW]

the KeyValue object this RelationStem acts on behalf of. @return [Orchestrate::KeyValue]

type[RW]

the type of relation this RelationStem interacts with. @return [String]

Public Class Methods

new(kv_item, type_name) click to toggle source

Instantiates a new RelationStem @param kv_item [Orchestrate::KeyValue] the KeyValue object this RelationStem acts on behalf of. @param type_name [#to_s] the type of relation this RelationStem interacts with.

# File lib/orchestrate/graph.rb, line 33
def initialize(kv_item, type_name)
  @kv_item = kv_item
  @type = type_name.to_s
end

Public Instance Methods

<<(other_item_or_collection_name, other_key=nil) click to toggle source

[Creates a relationship between two objects](orchestrate.io/docs/api/#graph/put). Relations can span collections. @overload <<(key_value_item)

@param key_value_item [Orchestrate::KeyValue] The KeyValue item to create the relationship with.

@overload <<(collection_name, key_name)

@param collection_name [#to_s] The collection which the other item belongs to.
@param key_name [#to_s] The key of the other item.

@return [Orchestrate::API::Response]

# 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
Also aliased as: push
[](type_n) click to toggle source

Adds depth to the retrieval of related items. @param type_n [#to_s] The kind of the relation for the second layer of depth to retreive results for. @return [Traversal]

# File lib/orchestrate/graph.rb, line 77
def [](type_n)
  Traversal.new(kv_item, [type, type_n.to_s])
end
delete(other_item_or_collection_name, other_key=nil) click to toggle source

[Deletes a relationship between two objects](orchestrate.io/docs/api/#graph/delete29). @overload delete(key_value_item)

@param key_value_item [Orchestrate::KeyValue] The KeyValue item to create the relationship with.

@overload delete(collection_name, key_name)

@param collection_name [#to_s] The collection which the other item belongs to.
@param key_name [#to_s] The key of the other item.

@return [Orchestrate::API::Response]

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

[Retrieves the related items](orchestrate.io/api/graph), and iterates over each item in the result. Used as the basis for Enumerable methods. @overload each

@return [Enumerator]

@overload each(&block)

@yieldparam [Orchestrate::KeyValue] key_value The KeyValue item
# File lib/orchestrate/graph.rb, line 90
def each(&block)
  Traversal.new(kv_item, [type]).each(&block)
end
perform(api_method, *args) click to toggle source

Calls a method on the KeyValue’s Collection’s API Client, providing the relation type. @param api_method [Symbol] The method on the client to call. @param args [#to_s, to_json, Hash] The remaining arguments for the specified method. @return [API::Response]

# File lib/orchestrate/graph.rb, line 42
def perform(api_method, *args)
  kv_item.perform(api_method, type, *args)
end
push(other_item_or_collection_name, other_key=nil)
Alias for: <<

Private Instance Methods

get_collection_and_key(item_or_collection, key) click to toggle source
# File lib/orchestrate/graph.rb, line 95
def get_collection_and_key(item_or_collection, key)
  if item_or_collection.kind_of?(KeyValue)
    collection = item_or_collection.collection_name
    key = item_or_collection.key
  else
    collection = item_or_collection
  end
  [collection, key]
end