arangorb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/ArangoRB.gemspec +18 -0
 - data/Gemfile +7 -0
 - data/LICENSE +21 -0
 - data/README.md +501 -0
 - data/lib/ArangoRB_AQL.rb +202 -0
 - data/lib/ArangoRB_Col.rb +350 -0
 - data/lib/ArangoRB_DB.rb +170 -0
 - data/lib/ArangoRB_Doc.rb +297 -0
 - data/lib/ArangoRB_Edg.rb +157 -0
 - data/lib/ArangoRB_Gra.rb +168 -0
 - data/lib/ArangoRB_Ser.rb +64 -0
 - data/lib/ArangoRB_Tra.rb +132 -0
 - data/lib/ArangoRB_Ver.rb +138 -0
 - data/lib/arangorb.rb +10 -0
 - data/spec/arangoRB_helper.rb +9 -0
 - data/spec/lib/arangoAQL_helper.rb +83 -0
 - data/spec/lib/arangoC_helper.rb +149 -0
 - data/spec/lib/arangoDB_helper.rb +119 -0
 - data/spec/lib/arangoDoc_helper.rb +92 -0
 - data/spec/lib/arangoE_helper.rb +70 -0
 - data/spec/lib/arangoG_helper.rb +92 -0
 - data/spec/lib/arangoS_helper.rb +28 -0
 - data/spec/lib/arangoT_helper.rb +67 -0
 - data/spec/lib/arangoV_helper.rb +81 -0
 - data/spec/spec_helper.rb +6 -0
 - metadata +92 -0
 
    
        data/lib/ArangoRB_DB.rb
    ADDED
    
    | 
         @@ -0,0 +1,170 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # === DATABASE ===
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class ArangoDB < ArangoS
         
     | 
| 
      
 4 
     | 
    
         
            +
              def initialize(database: @@database)
         
     | 
| 
      
 5 
     | 
    
         
            +
                if database.is_a?(String)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @database = database
         
     | 
| 
      
 7 
     | 
    
         
            +
                else
         
     | 
| 
      
 8 
     | 
    
         
            +
                  raise "database should be a String, not a #{database.class}"
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              attr_reader :database
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              # === GET ===
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def self.info
         
     | 
| 
      
 17 
     | 
    
         
            +
                result = get("/_api/database/current")
         
     | 
| 
      
 18 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : result["result"]
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              # === POST ===
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              def create(username: nil, passwd: nil, users: nil)
         
     | 
| 
      
 24 
     | 
    
         
            +
                body = {
         
     | 
| 
      
 25 
     | 
    
         
            +
                  "name" => @database,
         
     | 
| 
      
 26 
     | 
    
         
            +
                  "username" => username,
         
     | 
| 
      
 27 
     | 
    
         
            +
                  "passwd" => passwd,
         
     | 
| 
      
 28 
     | 
    
         
            +
                  "users" => users
         
     | 
| 
      
 29 
     | 
    
         
            +
                }
         
     | 
| 
      
 30 
     | 
    
         
            +
                body = body.delete_if{|k,v| v.nil?}.to_json
         
     | 
| 
      
 31 
     | 
    
         
            +
                new_DB = { :body => body }
         
     | 
| 
      
 32 
     | 
    
         
            +
                result = self.class.post("/_api/database", new_DB)
         
     | 
| 
      
 33 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDB.new(database: @database)
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              # === DELETE ===
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              def destroy
         
     | 
| 
      
 39 
     | 
    
         
            +
                result = self.class.delete("/_api/database/#{@database}")
         
     | 
| 
      
 40 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : result["result"]
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              # === LISTS ===
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def self.databases(user: nil)
         
     | 
| 
      
 46 
     | 
    
         
            +
                result = user.nil? ? get("/_api/database") : get("/_api/database/#{user}")
         
     | 
| 
      
 47 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : result["result"].map{|x| ArangoDB.new(database: x)}
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              def collections(excludeSystem: true)
         
     | 
| 
      
 51 
     | 
    
         
            +
                query = { "excludeSystem": excludeSystem }.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 52 
     | 
    
         
            +
                new_Document = { :query => query }
         
     | 
| 
      
 53 
     | 
    
         
            +
                result = self.class.get("/_db/#{@database}/_api/collection", new_Document)
         
     | 
| 
      
 54 
     | 
    
         
            +
                if @@verbose
         
     | 
| 
      
 55 
     | 
    
         
            +
                  return result
         
     | 
| 
      
 56 
     | 
    
         
            +
                else
         
     | 
| 
      
 57 
     | 
    
         
            +
                  if result["error"]
         
     | 
| 
      
 58 
     | 
    
         
            +
                    return result["errorMessage"]
         
     | 
| 
      
 59 
     | 
    
         
            +
                  else
         
     | 
| 
      
 60 
     | 
    
         
            +
                    return result["result"].map{|x| ArangoC.new(database: @database, collection: x["name"])}
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              def graphs
         
     | 
| 
      
 66 
     | 
    
         
            +
                result = self.class.get("/_db/#{@database}/_api/gharial")
         
     | 
| 
      
 67 
     | 
    
         
            +
                if @@verbose
         
     | 
| 
      
 68 
     | 
    
         
            +
                  return result
         
     | 
| 
      
 69 
     | 
    
         
            +
                else
         
     | 
| 
      
 70 
     | 
    
         
            +
                  if result["error"]
         
     | 
| 
      
 71 
     | 
    
         
            +
                    return result["errorMessage"]
         
     | 
| 
      
 72 
     | 
    
         
            +
                  else
         
     | 
| 
      
 73 
     | 
    
         
            +
                    return result["graphs"].map{|x| ArangoG.new(database: @database, graph: x["_key"], edgeDefinitions: x["edgeDefinitions"], orphanCollections: x["orphanCollections"])}
         
     | 
| 
      
 74 
     | 
    
         
            +
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
              def functions
         
     | 
| 
      
 79 
     | 
    
         
            +
                self.class.get("/_db/#{@database}/_api/aqlfunction").parsed_response
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
              # === QUERY ===
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
              def propertiesQuery
         
     | 
| 
      
 85 
     | 
    
         
            +
                result = self.class.get("/_db/#{@database}/_api/query/properties").parsed_response
         
     | 
| 
      
 86 
     | 
    
         
            +
                return_result(result)
         
     | 
| 
      
 87 
     | 
    
         
            +
              end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
              def currentQuery
         
     | 
| 
      
 90 
     | 
    
         
            +
                self.class.get("/_db/#{@database}/_api/query/current").parsed_response
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
              def slowQuery
         
     | 
| 
      
 94 
     | 
    
         
            +
                self.class.get("/_db/#{@database}/_api/query/slow").parsed_response
         
     | 
| 
      
 95 
     | 
    
         
            +
              end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
              def stopSlowQuery
         
     | 
| 
      
 98 
     | 
    
         
            +
                result = self.class.delete("/_db/#{@database}/_api/query/slow").parsed_response
         
     | 
| 
      
 99 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : true
         
     | 
| 
      
 100 
     | 
    
         
            +
              end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
              def killQuery(id:)
         
     | 
| 
      
 103 
     | 
    
         
            +
                result = self.class.delete("/_db/#{@database}/_api/query/#{id}").parsed_response
         
     | 
| 
      
 104 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : true
         
     | 
| 
      
 105 
     | 
    
         
            +
              end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
              def changePropertiesQuery(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil)
         
     | 
| 
      
 108 
     | 
    
         
            +
                body = {
         
     | 
| 
      
 109 
     | 
    
         
            +
                  "slowQueryThreshold" => slowQueryThreshold,
         
     | 
| 
      
 110 
     | 
    
         
            +
                  "enabled" => enabled,
         
     | 
| 
      
 111 
     | 
    
         
            +
                  "maxSlowQueries" => maxSlowQueries,
         
     | 
| 
      
 112 
     | 
    
         
            +
                  "trackSlowQueries" => trackSlowQueries,
         
     | 
| 
      
 113 
     | 
    
         
            +
                  "maxQueryStringLength" => maxQueryStringLength
         
     | 
| 
      
 114 
     | 
    
         
            +
                }.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 115 
     | 
    
         
            +
                new_Document = { :body => body.to_json }
         
     | 
| 
      
 116 
     | 
    
         
            +
                result = self.class.put("/_db/#{@database}/_api/query/properties", new_Document).parsed_response
         
     | 
| 
      
 117 
     | 
    
         
            +
                return_result(result)
         
     | 
| 
      
 118 
     | 
    
         
            +
              end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
            # === CACHE ===
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
              def clearCache
         
     | 
| 
      
 123 
     | 
    
         
            +
                result = self.class.delete("/_db/#{@database}/_api/query-cache").parsed_response
         
     | 
| 
      
 124 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : true
         
     | 
| 
      
 125 
     | 
    
         
            +
              end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
              def propertyCache
         
     | 
| 
      
 128 
     | 
    
         
            +
                self.class.get("/_db/#{@database}/_api/query-cache/properties").parsed_response
         
     | 
| 
      
 129 
     | 
    
         
            +
              end
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
              def changePropertyCache(mode: nil, maxResults: nil)
         
     | 
| 
      
 132 
     | 
    
         
            +
                body = { "mode" => mode, "maxResults" => maxResults }.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 133 
     | 
    
         
            +
                new_Document = { :body => body.to_json }
         
     | 
| 
      
 134 
     | 
    
         
            +
                self.class.put("/_db/#{@database}/_api/query-cache/properties", new_Document).parsed_response
         
     | 
| 
      
 135 
     | 
    
         
            +
              end
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
              # === AQL FUNCTION ===
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
              def createFunction(code:, name:, isDeterministic: nil)
         
     | 
| 
      
 140 
     | 
    
         
            +
                body = {
         
     | 
| 
      
 141 
     | 
    
         
            +
                  "code" => code,
         
     | 
| 
      
 142 
     | 
    
         
            +
                  "name" => name,
         
     | 
| 
      
 143 
     | 
    
         
            +
                  "isDeterministic" => isDeterministic
         
     | 
| 
      
 144 
     | 
    
         
            +
                }.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 145 
     | 
    
         
            +
                new_Document = { :body => body.to_json }
         
     | 
| 
      
 146 
     | 
    
         
            +
                result = self.class.post("/_db/#{@database}/_api/aqlfunction", new_Document).parsed_response
         
     | 
| 
      
 147 
     | 
    
         
            +
                return_result(result)
         
     | 
| 
      
 148 
     | 
    
         
            +
              end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
              def deleteFunction(name:)
         
     | 
| 
      
 151 
     | 
    
         
            +
                result = self.class.delete("/_db/#{@database}/_api/aqlfunction/#{name}")
         
     | 
| 
      
 152 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : true
         
     | 
| 
      
 153 
     | 
    
         
            +
              end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
              # === UTILITY ===
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
              def return_result(result)
         
     | 
| 
      
 158 
     | 
    
         
            +
                if @@verbose
         
     | 
| 
      
 159 
     | 
    
         
            +
                  result
         
     | 
| 
      
 160 
     | 
    
         
            +
                else
         
     | 
| 
      
 161 
     | 
    
         
            +
                  if result["error"]
         
     | 
| 
      
 162 
     | 
    
         
            +
                    result["errorMessage"]
         
     | 
| 
      
 163 
     | 
    
         
            +
                  else
         
     | 
| 
      
 164 
     | 
    
         
            +
                    result.delete("error")
         
     | 
| 
      
 165 
     | 
    
         
            +
                    result.delete("code")
         
     | 
| 
      
 166 
     | 
    
         
            +
                    result
         
     | 
| 
      
 167 
     | 
    
         
            +
                  end
         
     | 
| 
      
 168 
     | 
    
         
            +
                end
         
     | 
| 
      
 169 
     | 
    
         
            +
              end
         
     | 
| 
      
 170 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/ArangoRB_Doc.rb
    ADDED
    
    | 
         @@ -0,0 +1,297 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # ==== DOCUMENT ====
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class ArangoDoc < ArangoS
         
     | 
| 
      
 4 
     | 
    
         
            +
              def initialize(key: nil, collection: @@collection, database: @@database, body: {}, from: nil, to: nil)
         
     | 
| 
      
 5 
     | 
    
         
            +
                if collection.is_a?(String)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @collection = collection
         
     | 
| 
      
 7 
     | 
    
         
            +
                elsif collection.is_a?(ArangoC)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @collection = collection.collection
         
     | 
| 
      
 9 
     | 
    
         
            +
                else
         
     | 
| 
      
 10 
     | 
    
         
            +
                  raise "collection should be a String or an ArangoC instance, not a #{collection.class}"
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                if database.is_a?(String)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @database = database
         
     | 
| 
      
 15 
     | 
    
         
            +
                else
         
     | 
| 
      
 16 
     | 
    
         
            +
                  raise "database should be a String, not a #{database.class}"
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                if key.is_a?(String) || key.nil?
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @key = key
         
     | 
| 
      
 21 
     | 
    
         
            +
                  unless key.nil?
         
     | 
| 
      
 22 
     | 
    
         
            +
                    body["_key"] = @key
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @id = "#{@collection}/#{@key}"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                else
         
     | 
| 
      
 26 
     | 
    
         
            +
                  raise "key should be a String, not a #{key.class}"
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                if body.is_a?(Hash)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @body = body
         
     | 
| 
      
 31 
     | 
    
         
            +
                else
         
     | 
| 
      
 32 
     | 
    
         
            +
                  raise "body should be a Hash, not a #{body.class}"
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                if from.is_a?(String)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  @body["_from"] = from
         
     | 
| 
      
 37 
     | 
    
         
            +
                elsif from.is_a?(ArangoDoc)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  @body["_from"] = from.id
         
     | 
| 
      
 39 
     | 
    
         
            +
                elsif from.nil?
         
     | 
| 
      
 40 
     | 
    
         
            +
                else
         
     | 
| 
      
 41 
     | 
    
         
            +
                  raise "from should be a String or an ArangoDoc instance, not a #{from.class}"
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                if to.is_a?(String)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  @body["_to"] = to
         
     | 
| 
      
 46 
     | 
    
         
            +
                elsif to.is_a?(ArangoDoc)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @body["_to"] = to.id
         
     | 
| 
      
 48 
     | 
    
         
            +
                elsif to.nil?
         
     | 
| 
      
 49 
     | 
    
         
            +
                else
         
     | 
| 
      
 50 
     | 
    
         
            +
                  raise "to should be a String or an ArangoDoc instance, not a #{to.class}"
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
              attr_reader :key, :id, :body, :collection, :database
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              # === GET ===
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              def retrieve
         
     | 
| 
      
 59 
     | 
    
         
            +
                result = self.class.get("/_db/#{@database}/_api/document/#{@id}").parsed_response
         
     | 
| 
      
 60 
     | 
    
         
            +
                if @@verbose
         
     | 
| 
      
 61 
     | 
    
         
            +
                  @body = result unless result["error"]
         
     | 
| 
      
 62 
     | 
    
         
            +
                  result
         
     | 
| 
      
 63 
     | 
    
         
            +
                else
         
     | 
| 
      
 64 
     | 
    
         
            +
                  if result["error"]
         
     | 
| 
      
 65 
     | 
    
         
            +
                    result["errorMessage"]
         
     | 
| 
      
 66 
     | 
    
         
            +
                  else
         
     | 
| 
      
 67 
     | 
    
         
            +
                    @body = result
         
     | 
| 
      
 68 
     | 
    
         
            +
                    self
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
              def retrieve_edges(collection: , direction: nil)
         
     | 
| 
      
 74 
     | 
    
         
            +
                query = {"vertex" => @id, "direction" => direction }.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 75 
     | 
    
         
            +
                new_Document = { :query => query }
         
     | 
| 
      
 76 
     | 
    
         
            +
                collection = collection.is_a?(String) ? collection : collection.collection
         
     | 
| 
      
 77 
     | 
    
         
            +
                result = self.class.get("/_db/#{@database}/_api/edges/#{collection}", new_Document).parsed_response
         
     | 
| 
      
 78 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : result["edges"].map{|edge|
         
     | 
| 
      
 79 
     | 
    
         
            +
                  ArangoDoc.new(key: edge["_key"], collection: collection, database: @database, body: edge)
         
     | 
| 
      
 80 
     | 
    
         
            +
                }
         
     | 
| 
      
 81 
     | 
    
         
            +
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
              def in(collection)
         
     | 
| 
      
 84 
     | 
    
         
            +
                self.retrieve_edges collection: collection, direction: "in"
         
     | 
| 
      
 85 
     | 
    
         
            +
              end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
              def out(collection)
         
     | 
| 
      
 88 
     | 
    
         
            +
                self.retrieve_edges collection: collection, direction: "out"
         
     | 
| 
      
 89 
     | 
    
         
            +
              end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
              def any(collection)
         
     | 
| 
      
 92 
     | 
    
         
            +
                self.retrieve_edges collection: collection
         
     | 
| 
      
 93 
     | 
    
         
            +
              end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
              def from
         
     | 
| 
      
 96 
     | 
    
         
            +
                result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_from"]}").parsed_response
         
     | 
| 
      
 97 
     | 
    
         
            +
                collection = result["_id"].split("/")[0]
         
     | 
| 
      
 98 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDoc.new(key: result["_key"], collection: collection, database: @database, body: result)
         
     | 
| 
      
 99 
     | 
    
         
            +
              end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
              def to
         
     | 
| 
      
 102 
     | 
    
         
            +
                result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_to"]}").parsed_response
         
     | 
| 
      
 103 
     | 
    
         
            +
                collection = result["_id"].split("/")[0]
         
     | 
| 
      
 104 
     | 
    
         
            +
                @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDoc.new(key: result["_key"], collection: collection, database: @database, body: result)
         
     | 
| 
      
 105 
     | 
    
         
            +
              end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
              # def header
         
     | 
| 
      
 108 
     | 
    
         
            +
              #   result = self.class.head("/_db/#{@database}/_api/document/#{@id}", follow_redirects: true, maintain_method_across_redirects: true)
         
     | 
| 
      
 109 
     | 
    
         
            +
              #   @@verbose ? result : result["error"] ? result["errorMessage"] : result
         
     | 
| 
      
 110 
     | 
    
         
            +
              # end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
            # === POST ====
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
              def create(body: @body, waitForSync: nil, returnNew: nil, database: @database, collection: @collection)
         
     | 
| 
      
 115 
     | 
    
         
            +
                query = {"waitForSync" => waitForSync, "returnNew" => returnNew}.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 116 
     | 
    
         
            +
                unless body.is_a? Array
         
     | 
| 
      
 117 
     | 
    
         
            +
                  body["_key"] = @key if body["_key"].nil? && !@key.nil?
         
     | 
| 
      
 118 
     | 
    
         
            +
                  new_Document = { :body => body.to_json, :query => query }
         
     | 
| 
      
 119 
     | 
    
         
            +
                  result = self.class.post("/_db/#{database}/_api/document/#{collection}", new_Document).parsed_response
         
     | 
| 
      
 120 
     | 
    
         
            +
                  return_result(result, body)
         
     | 
| 
      
 121 
     | 
    
         
            +
                else
         
     | 
| 
      
 122 
     | 
    
         
            +
                  new_Document = { :body => body.to_json, :query => query }
         
     | 
| 
      
 123 
     | 
    
         
            +
                  result = self.class.post("/_db/#{database}/_api/document/#{collection}", new_Document).parsed_response
         
     | 
| 
      
 124 
     | 
    
         
            +
                  i = -1
         
     | 
| 
      
 125 
     | 
    
         
            +
                  return @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDoc.new(key: x["_key"], collection: collection, database: database, body: body[i+=1])}
         
     | 
| 
      
 126 
     | 
    
         
            +
                end
         
     | 
| 
      
 127 
     | 
    
         
            +
              end
         
     | 
| 
      
 128 
     | 
    
         
            +
              alias create_document create
         
     | 
| 
      
 129 
     | 
    
         
            +
              alias create_vertex create
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
              def self.create(body: {}, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection)
         
     | 
| 
      
 132 
     | 
    
         
            +
                collection = collection.is_a?(String) ? collection : collection.collection
         
     | 
| 
      
 133 
     | 
    
         
            +
                database = database.is_a?(String) ? database : database.database
         
     | 
| 
      
 134 
     | 
    
         
            +
                query = {"waitForSync" => waitForSync, "returnNew" => returnNew}.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 135 
     | 
    
         
            +
                unless body.is_a? Array
         
     | 
| 
      
 136 
     | 
    
         
            +
                  body["_key"] = @key if body["_key"].nil? && !@key.nil?
         
     | 
| 
      
 137 
     | 
    
         
            +
                  new_Document = { :body => body.to_json, :query => query }
         
     | 
| 
      
 138 
     | 
    
         
            +
                  result = post("/_db/#{database}/_api/document/#{collection}", new_Document).parsed_response
         
     | 
| 
      
 139 
     | 
    
         
            +
                  self.return_result(result, body)
         
     | 
| 
      
 140 
     | 
    
         
            +
                else
         
     | 
| 
      
 141 
     | 
    
         
            +
                  new_Document = { :body => body.to_json, :query => query }
         
     | 
| 
      
 142 
     | 
    
         
            +
                  result = post("/_db/#{database}/_api/document/#{collection}", new_Document).parsed_response
         
     | 
| 
      
 143 
     | 
    
         
            +
                  i = -1
         
     | 
| 
      
 144 
     | 
    
         
            +
                  return @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDoc.new(key: x["_key"], collection: collection, database: database, body: body[i+=1])}
         
     | 
| 
      
 145 
     | 
    
         
            +
                end
         
     | 
| 
      
 146 
     | 
    
         
            +
              end
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
              def create_edge(body: [{}], from:, to:, waitForSync: nil, returnNew: nil, database: @database, collection: @collection)
         
     | 
| 
      
 149 
     | 
    
         
            +
                edges = []
         
     | 
| 
      
 150 
     | 
    
         
            +
                from = [from] unless from.is_a? Array
         
     | 
| 
      
 151 
     | 
    
         
            +
                to = [to] unless to.is_a? Array
         
     | 
| 
      
 152 
     | 
    
         
            +
                body = [body] unless body.is_a? Array
         
     | 
| 
      
 153 
     | 
    
         
            +
                body.each do |b|
         
     | 
| 
      
 154 
     | 
    
         
            +
                  from.each do |f|
         
     | 
| 
      
 155 
     | 
    
         
            +
                    b["_from"] = f.is_a?(String) ? f : f.id
         
     | 
| 
      
 156 
     | 
    
         
            +
                    to.each do |t|
         
     | 
| 
      
 157 
     | 
    
         
            +
                      b["_to"] = t.is_a?(String) ? t : t.id
         
     | 
| 
      
 158 
     | 
    
         
            +
                      edges << b.clone
         
     | 
| 
      
 159 
     | 
    
         
            +
                    end
         
     | 
| 
      
 160 
     | 
    
         
            +
                  end
         
     | 
| 
      
 161 
     | 
    
         
            +
                end
         
     | 
| 
      
 162 
     | 
    
         
            +
                edges = edges[0] if edges.length == 1
         
     | 
| 
      
 163 
     | 
    
         
            +
                create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
         
     | 
| 
      
 164 
     | 
    
         
            +
                # ArangoDoc.create_edge(body: body, from: from, to: to, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
         
     | 
| 
      
 165 
     | 
    
         
            +
              end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
              def self.create_edge(body: {}, from:, to:, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection)
         
     | 
| 
      
 168 
     | 
    
         
            +
                edges = []
         
     | 
| 
      
 169 
     | 
    
         
            +
                from = [from] unless from.is_a? Array
         
     | 
| 
      
 170 
     | 
    
         
            +
                to = [to] unless to.is_a? Array
         
     | 
| 
      
 171 
     | 
    
         
            +
                body = [body] unless body.is_a? Array
         
     | 
| 
      
 172 
     | 
    
         
            +
                body.each do |b|
         
     | 
| 
      
 173 
     | 
    
         
            +
                  from.each do |f|
         
     | 
| 
      
 174 
     | 
    
         
            +
                    b["_from"] = f.is_a?(String) ? f : f.id
         
     | 
| 
      
 175 
     | 
    
         
            +
                    to.each do |t|
         
     | 
| 
      
 176 
     | 
    
         
            +
                      b["_to"] = t.is_a?(String) ? t : t.id
         
     | 
| 
      
 177 
     | 
    
         
            +
                      edges << b.clone
         
     | 
| 
      
 178 
     | 
    
         
            +
                    end
         
     | 
| 
      
 179 
     | 
    
         
            +
                  end
         
     | 
| 
      
 180 
     | 
    
         
            +
                end
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                edges = edges[0] if edges.length == 1
         
     | 
| 
      
 183 
     | 
    
         
            +
                self.create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
         
     | 
| 
      
 184 
     | 
    
         
            +
              end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
            # === MODIFY ===
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
              def replace(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil)
         
     | 
| 
      
 189 
     | 
    
         
            +
                query = {
         
     | 
| 
      
 190 
     | 
    
         
            +
                  "waitForSync" => waitForSync,
         
     | 
| 
      
 191 
     | 
    
         
            +
                  "returnNew" => returnNew,
         
     | 
| 
      
 192 
     | 
    
         
            +
                  "returnOld" => returnOld,
         
     | 
| 
      
 193 
     | 
    
         
            +
                  "ignoreRevs" => ignoreRevs
         
     | 
| 
      
 194 
     | 
    
         
            +
                }.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 195 
     | 
    
         
            +
                new_Document = { :body => body.to_json, :query => query }
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
                unless body.is_a? Array
         
     | 
| 
      
 198 
     | 
    
         
            +
                  result = self.class.put("/_db/#{@database}/_api/document/#{@id}", new_Document).parsed_response
         
     | 
| 
      
 199 
     | 
    
         
            +
                  return_result(result, body)
         
     | 
| 
      
 200 
     | 
    
         
            +
                else
         
     | 
| 
      
 201 
     | 
    
         
            +
                  result = self.class.put("/_db/#{@database}/_api/document/#{@collection}", new_Document).parsed_response
         
     | 
| 
      
 202 
     | 
    
         
            +
                  i = -1
         
     | 
| 
      
 203 
     | 
    
         
            +
                  return @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDoc.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
         
     | 
| 
      
 204 
     | 
    
         
            +
                end
         
     | 
| 
      
 205 
     | 
    
         
            +
              end
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
              def update(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil, keepNull: nil, mergeObjects: nil)
         
     | 
| 
      
 208 
     | 
    
         
            +
                query = {
         
     | 
| 
      
 209 
     | 
    
         
            +
                  "waitForSync" => waitForSync,
         
     | 
| 
      
 210 
     | 
    
         
            +
                  "returnNew" => returnNew,
         
     | 
| 
      
 211 
     | 
    
         
            +
                  "returnOld" => returnOld,
         
     | 
| 
      
 212 
     | 
    
         
            +
                  "ignoreRevs" => ignoreRevs,
         
     | 
| 
      
 213 
     | 
    
         
            +
                  "keepNull" => keepNull,
         
     | 
| 
      
 214 
     | 
    
         
            +
                  "mergeObjects" => mergeObjects
         
     | 
| 
      
 215 
     | 
    
         
            +
                }.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 216 
     | 
    
         
            +
                new_Document = { :body => body.to_json, :query => query }
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                unless body.is_a? Array
         
     | 
| 
      
 219 
     | 
    
         
            +
                  result = self.class.patch("/_db/#{@database}/_api/document/#{@id}", new_Document).parsed_response
         
     | 
| 
      
 220 
     | 
    
         
            +
                  if @@verbose
         
     | 
| 
      
 221 
     | 
    
         
            +
                    unless result["error"]
         
     | 
| 
      
 222 
     | 
    
         
            +
                      @key = result["_key"]
         
     | 
| 
      
 223 
     | 
    
         
            +
                      @id = "#{@collection}/#{@key}"
         
     | 
| 
      
 224 
     | 
    
         
            +
                      @body = body
         
     | 
| 
      
 225 
     | 
    
         
            +
                    end
         
     | 
| 
      
 226 
     | 
    
         
            +
                    result
         
     | 
| 
      
 227 
     | 
    
         
            +
                  else
         
     | 
| 
      
 228 
     | 
    
         
            +
                    if result["error"]
         
     | 
| 
      
 229 
     | 
    
         
            +
                      result["errorMessage"]
         
     | 
| 
      
 230 
     | 
    
         
            +
                    else
         
     | 
| 
      
 231 
     | 
    
         
            +
                      @key = result["_key"]
         
     | 
| 
      
 232 
     | 
    
         
            +
                      @id = "#{@collection}/#{@key}"
         
     | 
| 
      
 233 
     | 
    
         
            +
                      @body = @body.merge(body)
         
     | 
| 
      
 234 
     | 
    
         
            +
                      self
         
     | 
| 
      
 235 
     | 
    
         
            +
                    end
         
     | 
| 
      
 236 
     | 
    
         
            +
                  end
         
     | 
| 
      
 237 
     | 
    
         
            +
                else
         
     | 
| 
      
 238 
     | 
    
         
            +
                  result = self.class.patch("/_db/#{@database}/_api/document/#{@collection}", new_Document).parsed_response
         
     | 
| 
      
 239 
     | 
    
         
            +
                  i = -1
         
     | 
| 
      
 240 
     | 
    
         
            +
                  return @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDoc.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
         
     | 
| 
      
 241 
     | 
    
         
            +
                end
         
     | 
| 
      
 242 
     | 
    
         
            +
              end
         
     | 
| 
      
 243 
     | 
    
         
            +
             
     | 
| 
      
 244 
     | 
    
         
            +
            # === DELETE ===
         
     | 
| 
      
 245 
     | 
    
         
            +
             
     | 
| 
      
 246 
     | 
    
         
            +
              def destroy(body: nil, waitForSync: nil, ignoreRevs: nil, returnOld: nil)
         
     | 
| 
      
 247 
     | 
    
         
            +
                query = {
         
     | 
| 
      
 248 
     | 
    
         
            +
                  "waitForSync" => waitForSync,
         
     | 
| 
      
 249 
     | 
    
         
            +
                  "returnOld" => returnOld,
         
     | 
| 
      
 250 
     | 
    
         
            +
                  "ignoreRevs" => ignoreRevs
         
     | 
| 
      
 251 
     | 
    
         
            +
                }.delete_if{|k,v| v.nil?}
         
     | 
| 
      
 252 
     | 
    
         
            +
                new_Document = { :query => query }
         
     | 
| 
      
 253 
     | 
    
         
            +
             
     | 
| 
      
 254 
     | 
    
         
            +
                unless body.is_a? Array
         
     | 
| 
      
 255 
     | 
    
         
            +
                  result = self.class.delete("/_db/#{@database}/_api/document/#{@id}", new_Document).parsed_response
         
     | 
| 
      
 256 
     | 
    
         
            +
                  @@verbose ? result : result["error"] ? result["errorMessage"] : true
         
     | 
| 
      
 257 
     | 
    
         
            +
                else
         
     | 
| 
      
 258 
     | 
    
         
            +
                  new_Document = { :body => body.to_json, :query => query }
         
     | 
| 
      
 259 
     | 
    
         
            +
                  result = self.class.delete("/_db/#{@database}/_api/document/#{@collection}", new_Document).parsed_response
         
     | 
| 
      
 260 
     | 
    
         
            +
                  return result
         
     | 
| 
      
 261 
     | 
    
         
            +
                end
         
     | 
| 
      
 262 
     | 
    
         
            +
              end
         
     | 
| 
      
 263 
     | 
    
         
            +
             
     | 
| 
      
 264 
     | 
    
         
            +
            # === UTILITY ===
         
     | 
| 
      
 265 
     | 
    
         
            +
             
     | 
| 
      
 266 
     | 
    
         
            +
              def return_result(result, body)
         
     | 
| 
      
 267 
     | 
    
         
            +
                if @@verbose
         
     | 
| 
      
 268 
     | 
    
         
            +
                  unless result["error"]
         
     | 
| 
      
 269 
     | 
    
         
            +
                    @key = result["_key"]
         
     | 
| 
      
 270 
     | 
    
         
            +
                    @id = "#{@collection}/#{@key}"
         
     | 
| 
      
 271 
     | 
    
         
            +
                    @body = body
         
     | 
| 
      
 272 
     | 
    
         
            +
                  end
         
     | 
| 
      
 273 
     | 
    
         
            +
                  result
         
     | 
| 
      
 274 
     | 
    
         
            +
                else
         
     | 
| 
      
 275 
     | 
    
         
            +
                  if result["error"]
         
     | 
| 
      
 276 
     | 
    
         
            +
                    result["errorMessage"]
         
     | 
| 
      
 277 
     | 
    
         
            +
                  else
         
     | 
| 
      
 278 
     | 
    
         
            +
                    @key = result["_key"]
         
     | 
| 
      
 279 
     | 
    
         
            +
                    @id = "#{@collection}/#{@key}"
         
     | 
| 
      
 280 
     | 
    
         
            +
                    @body = body
         
     | 
| 
      
 281 
     | 
    
         
            +
                    self
         
     | 
| 
      
 282 
     | 
    
         
            +
                  end
         
     | 
| 
      
 283 
     | 
    
         
            +
                end
         
     | 
| 
      
 284 
     | 
    
         
            +
              end
         
     | 
| 
      
 285 
     | 
    
         
            +
             
     | 
| 
      
 286 
     | 
    
         
            +
              def self.return_result(result, body)
         
     | 
| 
      
 287 
     | 
    
         
            +
                if @@verbose
         
     | 
| 
      
 288 
     | 
    
         
            +
                  result
         
     | 
| 
      
 289 
     | 
    
         
            +
                else
         
     | 
| 
      
 290 
     | 
    
         
            +
                  if result["error"]
         
     | 
| 
      
 291 
     | 
    
         
            +
                    result["errorMessage"]
         
     | 
| 
      
 292 
     | 
    
         
            +
                  else
         
     | 
| 
      
 293 
     | 
    
         
            +
                    ArangoDoc.new key: result["_key"], collection: result["_id"].split("/")[0], body: body
         
     | 
| 
      
 294 
     | 
    
         
            +
                  end
         
     | 
| 
      
 295 
     | 
    
         
            +
                end
         
     | 
| 
      
 296 
     | 
    
         
            +
              end
         
     | 
| 
      
 297 
     | 
    
         
            +
            end
         
     |