Module: Arango::Graph::ClassMethods
- Defined in:
- lib/arango/graph/class_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#all(database: Arango.current_database) ⇒ Array<Arango::Graph::Base>
Retrieves all graphs from the database.
- #create(is_smart: @is_smart, smart_graph_attribute: @smart_graph_attribute, number_of_shards: @number_of_shards) ⇒ Object
-
#delete(name:, database: Arango.current_database) ⇒ Object
Removes a graph.
-
#exists?(name:, database: Arango.current_database) ⇒ Boolean
Check if graph exists.
- #from_h(graph_hash, database: Arango.current_database) ⇒ Object
-
#from_results(graph_result, properties_result, database: Arango.current_database) ⇒ Arango::Graph::Base
Takes a Arango::Result and instantiates a Arango::Graph::Base object from it.
-
#get(name:, database: Arango.current_database) ⇒ Arango::Database
Get graph from the database.
-
#list(database: Arango.current_database) ⇒ Array<String>
Retrieves a list of all graphs.
Class Method Details
.extended(base) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/arango/graph/class_methods.rb', line 23 def self.extended(base) # Retrieves all graphs from the database. # @param exclude_system [Boolean] Optional, default true, exclude system graphs. # @param database [Arango::Database] # @return [Array<Arango::Graph::Base>] def all (database: Arango.current_database) result = Arango::Requests::Graph::ListAll.execute(server: database.server) result.graphs.map { |c| from_results({}, c.to_h, database: database) } end # Get graph from the database. # @param name [String] The name of the graph. # @param database [Arango::Database] # @return [Arango::Database] def get (name:, database: Arango.current_database) args = { graph: name } result = Arango::Requests::Graph::Get.execute(server: database.server, args: args) from_results({}, result.graph, database: database) end # Retrieves a list of all graphs. # @param exclude_system [Boolean] Optional, default true, exclude system graphs. # @param database [Arango::Database] # @return [Array<String>] List of graph names. def list (database: Arango.current_database) result = Arango::Requests::Graph::ListAll.execute(server: database.server) result.graphs.map { |c| c[:name] } end # Removes a graph. # @param name [String] The name of the graph. # @param database [Arango::Database] # @return nil def delete(name:, database: Arango.current_database) args = { graph: name } result = Arango::Requests::Graph::Delete.execute(server: database.server, args: args) end # Check if graph exists. # @param name [String] Name of the graph # @param database [Arango::Database] # @return [Boolean] def exists? (name:, database: Arango.current_database) args = { name: name } result = Arango::Requests::Graph::Get.execute(server: database.server, args: args) result.graphs.map { |c| c[:name] }.include?(name) end end |
Instance Method Details
#all(database: Arango.current_database) ⇒ Array<Arango::Graph::Base>
Retrieves all graphs from the database.
29 30 31 32 |
# File 'lib/arango/graph/class_methods.rb', line 29 def all (database: Arango.current_database) result = Arango::Requests::Graph::ListAll.execute(server: database.server) result.graphs.map { |c| from_results({}, c.to_h, database: database) } end |
#create(is_smart: @is_smart, smart_graph_attribute: @smart_graph_attribute, number_of_shards: @number_of_shards) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/arango/graph/class_methods.rb', line 73 def create(is_smart: @is_smart, smart_graph_attribute: @smart_graph_attribute, number_of_shards: @number_of_shards) body = { name: @name, edgeDefinitions: edge_definitions_raw, isSmart: is_smart, options: { smartGraphAttribute: smart_graph_attribute, numberOfShards: number_of_shards } } body[:options].delete_if{|k,v| v.nil?} body.delete(:options) if body[:options].empty? result = Arango::Requests::Graph::Create.execute(server: @database.server, body: body, key: :graph) return_element(result) end |
#delete(name:, database: Arango.current_database) ⇒ Object
Removes a graph.
57 58 59 60 |
# File 'lib/arango/graph/class_methods.rb', line 57 def delete(name:, database: Arango.current_database) args = { graph: name } result = Arango::Requests::Graph::Delete.execute(server: database.server, args: args) end |
#exists?(name:, database: Arango.current_database) ⇒ Boolean
Check if graph exists.
66 67 68 69 70 |
# File 'lib/arango/graph/class_methods.rb', line 66 def exists? (name:, database: Arango.current_database) args = { name: name } result = Arango::Requests::Graph::Get.execute(server: database.server, args: args) result.graphs.map { |c| c[:name] }.include?(name) end |
#from_h(graph_hash, database: Arango.current_database) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/arango/graph/class_methods.rb', line 4 def from_h(graph_hash, database: Arango.current_database) graph_hash = graph_hash.transform_keys { |k| k.to_s.underscore.to_sym } graph_hash.merge!(database: database) unless graph_hash.has_key?(:database) if graph_hash.has_key?(:properties) graph_hash[:name] = graph_hash[:properties].delete(:name) if graph_hash[:properties].has_key?(:name) end Arango::Graph::Base.new(**graph_hash) end |
#from_results(graph_result, properties_result, database: Arango.current_database) ⇒ Arango::Graph::Base
Takes a Arango::Result and instantiates a Arango::Graph::Base object from it.
17 18 19 20 21 |
# File 'lib/arango/graph/class_methods.rb', line 17 def from_results(graph_result, properties_result, database: Arango.current_database) hash = graph_result ? {}.merge(graph_result.to_h) : {} hash[:properties] = properties_result from_h(hash, database: database) end |
#get(name:, database: Arango.current_database) ⇒ Arango::Database
Get graph from the database.
38 39 40 41 42 |
# File 'lib/arango/graph/class_methods.rb', line 38 def get (name:, database: Arango.current_database) args = { graph: name } result = Arango::Requests::Graph::Get.execute(server: database.server, args: args) from_results({}, result.graph, database: database) end |
#list(database: Arango.current_database) ⇒ Array<String>
Retrieves a list of all graphs.
48 49 50 51 |
# File 'lib/arango/graph/class_methods.rb', line 48 def list (database: Arango.current_database) result = Arango::Requests::Graph::ListAll.execute(server: database.server) result.graphs.map { |c| c[:name] } end |