Module: Arango::Graph::InstanceMethods

Defined in:
lib/arango/graph/instance_methods.rb

Overview

Arango Graph InstanceMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



31
32
33
# File 'lib/arango/graph/instance_methods.rb', line 31

def database
  @database
end

Instance Method Details

#createArango::DocumentCollection

Stores the graph in the database.

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/arango/graph/instance_methods.rb', line 65

def create
  @name_changed = false
  @wait_for_sync_changed = false

  body = {}.merge(@attributes)
  body.merge!(@changed_attributes)

  @properties.each do |k, v|
    body[:options][k.to_s.camelize(:lower)] = v unless v.nil?
  end

  params = {}
  if @wait_for_sync_changed
    params[:waitForSync] = @wait_for_sync
  end
  result = Arango::Requests::Graph::Create.execute(server: @database.server, body: body, params: params)
  _update_attributes(result.graph)
  self
end

#deleteNilClass

Deletes a graph.

Returns:

  • (NilClass)


87
88
89
90
# File 'lib/arango/graph/instance_methods.rb', line 87

def delete
  args = { graph: @name }
  Arango::Requests::Graph::Delete.execute(server: @database.server, args: args)
end

#idObject



33
34
35
# File 'lib/arango/graph/instance_methods.rb', line 33

def id
  @changed_attributes[:_id] || @attributes[:_id]
end

#id=(i) ⇒ Object



37
38
39
# File 'lib/arango/graph/instance_methods.rb', line 37

def id=(i)
  @changed_attributes[:_id] = i
end

#initialize(database: Arango.current_database, name:, edge_definitions: [], is_smart: false, properties: {}) ⇒ Arango::Graph

Instantiate a new collection. For param description see the attributes descriptions. All params except name are optional.

Parameters:

  • name (String)

    The name of the collection.

  • database (Arango::Database) (defaults to: Arango.current_database)

    , defaults to Arango.current_database

  • edge_definitions (Array) (defaults to: [])

    of edge definitions

  • is_smart (Boolean) (defaults to: false)

    , optional, defaults to false

  • properties (Hash) (defaults to: {})

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/arango/graph/instance_methods.rb', line 15

def initialize(database: Arango.current_database,
               name:, edge_definitions: [], is_smart: false,
               properties: {})
  @attributes = { name: name, edge_definitions: edge_definitions }
  @changed_attributes = {}
  send(:database=, database)
  @aql = nil
  @batch_proc = nil
  _set_name(name)
  @name_changed = false
  @original_name = name
  @edge_definitions = edge_definitions
  @orphan_collections = []
  _set_properties(properties)
end

#nameObject



41
42
43
# File 'lib/arango/graph/instance_methods.rb', line 41

def name
  @changed_attributes[:name] || @attributes[:name]
end

#name=(n) ⇒ Object



45
46
47
48
# File 'lib/arango/graph/instance_methods.rb', line 45

def name=(n)
  @name_changed = true
  _set_name(n)
end

#revisionObject



50
51
52
# File 'lib/arango/graph/instance_methods.rb', line 50

def revision
  @properties[:_rev]
end

#to_hObject



54
55
56
# File 'lib/arango/graph/instance_methods.rb', line 54

def to_h
  @attributes.delete_if{|_,v| v.nil?}
end

#wait_for_sync=(n) ⇒ Object



58
59
60
61
# File 'lib/arango/graph/instance_methods.rb', line 58

def wait_for_sync=(n)
  @wait_for_sync_changed = true
  @properties[:wait_for_sync] = n
end