ashikawa-core 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5174468b7c49a72458d5d91bf9939caf77023f2c
4
- data.tar.gz: dc22ceaaacccfd9133638c4707eac3581b71e56d
3
+ metadata.gz: d94a6bf23847adaa62e95260d2c57e45fb8a0c8a
4
+ data.tar.gz: 3d033e741693a5a82b9c6aef68a9a26367a9d75e
5
5
  SHA512:
6
- metadata.gz: 690e9a24ebd4757b14992231d2601b314a9c27c3e7dcb85ceee47b571252cfdb9dcdc30f3b001b17b8ec81a94c25f807bf0acafc86418072bf4644753ecab9bf
7
- data.tar.gz: 458b6482db0c04a39b3616901765991f398801ea0db65978b921d439be91603c70f728b566ccaf81c5902394bbd2c75c7a6f8aee880f7b78a26b510209e4c61c
6
+ metadata.gz: 0eba07aba13e31a52f30b111481a3bcd6de186888f59553211bfd074112c3aca60a893674fb9aaa0759f36aca859671044898b4eacb1f78deecdffd672c05ab3
7
+ data.tar.gz: 087bd78cf960a174b4d892f6dfb4b6f03b81b483fb45622537758faed347f9006d6007fcbec27fc349bde9ef8dcdc65e2077847833a1322225e6d2c76193fc59
@@ -0,0 +1,8 @@
1
+ ---
2
+ rules:
3
+ copy_paste:
4
+ except:
5
+ - spec/**
6
+ documentation:
7
+ except:
8
+ - spec/**
@@ -1 +1 @@
1
- ruby-2.1.2
1
+ ruby-2.2.0
@@ -3,11 +3,11 @@ before_script:
3
3
  - "./spec/setup/arangodb.sh"
4
4
  rvm:
5
5
  - 1.9.3
6
- - 2.0.0
7
- - 2.1.2
6
+ - 2.1.5
7
+ - 2.2.0
8
8
  - jruby-1.7.12
9
9
  env:
10
- - ARANGODB_DISABLE_AUTHENTIFICATION=false VERSION=2.2
10
+ - ARANGODB_DISABLE_AUTHENTIFICATION=false VERSION=2.4
11
11
  script: bundle exec rake ci
12
12
  addons:
13
13
  code_climate:
@@ -1,3 +1,13 @@
1
+ # Version 0.14.0
2
+
3
+ **Codename: Armstrong**
4
+
5
+ * Making `add_vertex_collection` and `add_edge_definition` idempotent (#144, #139)
6
+ * Introduced `add_vertex_collection!` and `add_edge_definition!` which will raise errors
7
+ * Making error messages and error numbers from ArangoDB more visible in exceptions (#136)
8
+ * Small improvements to the docuemtation
9
+ * Running against Ruby 2.2.0 now
10
+
1
11
  # Version 0.13.1
2
12
 
3
13
  * **Important Bugfix: Please update immediately**
@@ -7,7 +17,7 @@
7
17
 
8
18
  **Codename: Galadriel**
9
19
 
10
- * Support for the [new Graph module](http://docs.arangodb.org/HttpGharial/README.html) in Arango 2.2 (#55)
20
+ * Support for the [new Graph module](http://docs.arangodb.com/HttpGharial/README.html) in Arango 2.2 (#55)
11
21
  * Fixed badge URL for Inch (#130)
12
22
  * **Deprecated** `Collection#create_edge` in favor of `EdgeCollection#add`
13
23
  * Sending the `X-Arango-Version` HTTP header with each request (#82)
data/README.md CHANGED
@@ -10,11 +10,11 @@
10
10
  | Gem Version | [![Gem Version](http://img.shields.io/gem/v/ashikawa-core.svg)](http://rubygems.org/gems/ashikawa-core)
11
11
  | Dependencies | [![Dependency Status](http://img.shields.io/gemnasium/triAGENS/ashikawa-core.svg)](https://gemnasium.com/triAGENS/ashikawa-core)
12
12
 
13
- Ashikawa Core is a Wrapper around the ArangoDB Rest API. It provides low level access and is intended to be used in ArangoDB ODMs and other projects related to the database. It is always working with the stable version of ArangoDB, this is currently version **2.2**.
13
+ Ashikawa Core is a Wrapper around the ArangoDB Rest API. It provides low level access and is intended to be used in ArangoDB ODMs and other projects related to the database. It is always working with the stable version of ArangoDB, this is currently version **2.4**.
14
14
 
15
15
  All tests run on Travis CI for the following versions of Ruby:
16
16
 
17
- * MRI 1.9.3, 2.0.0 and 2.1.2
17
+ * MRI 1.9.3, 2.1.5 and 2.2.0
18
18
  * JRuby 1.7.12
19
19
 
20
20
  ## How to install it?
@@ -5,8 +5,8 @@ require 'ashikawa-core/version'
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'ashikawa-core'
7
7
  gem.version = Ashikawa::Core::VERSION
8
- gem.authors = ['moonglum']
9
- gem.email = ['me@moonglum.net']
8
+ gem.authors = ['Lucas Dohmen', 'Dirk Breuer']
9
+ gem.email = ['lucas@arangodb.com', 'dirk@arangodb.com']
10
10
  gem.homepage = 'http://triagens.github.com/ashikawa-core'
11
11
  gem.summary = 'Ashikawa Core is a wrapper around the ArangoDB REST API'
12
12
  gem.description = 'Ashikawa Core is a wrapper around the ArangoDB REST API. It provides low level access and is intended to be used in ArangoDB ODMs and other tools.'
@@ -10,7 +10,8 @@ ClassVariable:
10
10
  exclude: []
11
11
  ControlParameter:
12
12
  enabled: true
13
- exclude: []
13
+ exclude:
14
+ - Ashikawa::Core::ClientError#initialize
14
15
  DataClump:
15
16
  enabled: true
16
17
  exclude: []
@@ -68,6 +69,7 @@ TooManyStatements:
68
69
  - Ashikawa::Core::FaradayFactory#faraday_for
69
70
  - Ashikawa::Core::ErrorResponse#on_complete
70
71
  - Ashikawa::Core::Figure#initialize
72
+ - Ashikawa::Core::ErrorResponse#resource_not_found_in_graph_scope
71
73
  max_statements: 6
72
74
  UncommunicativeMethodName:
73
75
  enabled: true
@@ -7,6 +7,8 @@ require 'ashikawa-core/exceptions/client_error/resource_not_found/collection_not
7
7
  require 'ashikawa-core/exceptions/client_error/resource_not_found/graph_not_found'
8
8
  require 'ashikawa-core/exceptions/client_error/bad_syntax'
9
9
  require 'ashikawa-core/exceptions/client_error/authentication_failed'
10
+ require 'ashikawa-core/exceptions/client_error/vertex_collection_already_present'
11
+ require 'ashikawa-core/exceptions/client_error/edge_collection_already_present'
10
12
  require 'ashikawa-core/exceptions/server_error'
11
13
  require 'ashikawa-core/exceptions/server_error/json_error'
12
14
 
@@ -41,7 +43,7 @@ module Ashikawa
41
43
  # @raise [ServerError] If the status code is any of the 5XX codes
42
44
  # @return nil
43
45
  def on_complete(env)
44
- @body = env[:body]
46
+ @body = env[:body] || {}
45
47
  @url = env[:url]
46
48
 
47
49
  case env[:status]
@@ -103,7 +105,7 @@ module Ashikawa
103
105
  when %r{\A(/_db/[^/]+)?/_api/index} then IndexNotFoundException
104
106
  when %r{\A(/_db/[^/]+)?/_api/gharial} then resource_not_found_in_graph_scope
105
107
  else ResourceNotFound
106
- end
108
+ end, error
107
109
  end
108
110
 
109
111
  # Raise fitting ResourceNotFoundException within the Graph module
@@ -116,8 +118,12 @@ module Ashikawa
116
118
  when 'graph not found' then GraphNotFoundException
117
119
  when 'collection not found' then CollectionNotFoundException
118
120
  when 'document not found' then DocumentNotFoundException
121
+ when 'collection used in orphans' then VertexCollectionAlreadyPresent
122
+ when 'collection used in edge def' then VertexCollectionAlreadyPresent
123
+ when 'multi use of edge collection in edge def' then EdgeCollectionAlreadyPresent
124
+ when 'edge collection already used in edge def' then EdgeCollectionAlreadyPresent
119
125
  else ResourceNotFound
120
- end
126
+ end, error
121
127
  end
122
128
 
123
129
  # Read the error message for the request
@@ -126,7 +132,7 @@ module Ashikawa
126
132
  # @return [String] The formatted error message
127
133
  # @api private
128
134
  def error
129
- "#{@body['errorNum']}: #{@body['errorMessage']}"
135
+ @body.empty? ? nil : "#{@body['errorNum']}: #{@body['errorMessage']}"
130
136
  end
131
137
  end
132
138
 
@@ -5,19 +5,19 @@ module Ashikawa
5
5
  class ClientError < RuntimeError
6
6
  # Create a new instance
7
7
  #
8
- # @param [Fixnum] status_code
8
+ # @param [String] message The error message
9
9
  # @return RuntimeError
10
10
  # @api private
11
- def initialize(status_code)
12
- @status_code = status_code
11
+ def initialize(message = nil)
12
+ super(message || default_error_message)
13
13
  end
14
14
 
15
- # String representation of the exception
15
+ # The default error message to be used. Can be overridden by sub classed
16
16
  #
17
- # @return String
17
+ # @return String the default error message
18
18
  # @api private
19
- def to_s
20
- @status_code
19
+ def default_error_message
20
+ '400 Bad Request'
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'ashikawa-core/exceptions/client_error.rb'
4
+
5
+ module Ashikawa
6
+ module Core
7
+ # This collection may occur when adding edge definitions
8
+ # to the graph. While creating edge definitions ArangoDB
9
+ # will create an edge collection. It has be unique for the
10
+ # current database. ArangoDB differentiates between two errors:
11
+ #
12
+ # 1. The edge collection is already used in the same graph (1920)
13
+ # 2. The edge collection is already used in another graph (1921)
14
+ class EdgeCollectionAlreadyPresent < ClientError
15
+ end
16
+ end
17
+ end
@@ -6,20 +6,12 @@ module Ashikawa
6
6
  # This Exception is thrown when you request
7
7
  # a resource that does not exist on the server
8
8
  class ResourceNotFound < ClientError
9
- # Create a new instance
10
- #
11
- # @return RuntimeError
12
- # @api private
13
- def initialize
14
- super(404)
15
- end
16
-
17
- # String representation of the exception
9
+ # The default message for this error.
18
10
  #
19
11
  # @return String
20
12
  # @api private
21
- def to_s
22
- 'Status 404: The Resource you requested was not found on the server'
13
+ def default_error_message
14
+ 'The Resource you requested was not found on the server'
23
15
  end
24
16
  end
25
17
  end
@@ -0,0 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'ashikawa-core/exceptions/client_error.rb'
4
+
5
+ module Ashikawa
6
+ module Core
7
+ # This exception is thrown when the vertex collection
8
+ # to be added is already member of the graph. There are
9
+ # two different error messages that can occur:
10
+ #
11
+ # 1. The vertex collection is already member of the orphans (1938)
12
+ # 2. The vertex collection is already member of an edge definition (1929)
13
+ class VertexCollectionAlreadyPresent < ClientError
14
+ end
15
+ end
16
+ end
@@ -10,7 +10,7 @@ module Ashikawa
10
10
  # @note All CRUD operations on related collections (edges and vertices) must be performed
11
11
  # through their corresponding graph class. Not doing so will eventually lead to inconsistency
12
12
  # and data corruption.
13
- # @see http://docs.arangodb.org/HttpGharial/README.html
13
+ # @see http://docs.arangodb.com/HttpGharial/README.html
14
14
  class Graph
15
15
  extend Forwardable
16
16
 
@@ -112,8 +112,25 @@ module Ashikawa
112
112
  # to the list of vertex collections.
113
113
  #
114
114
  # @param [String] collection_name The name of the vertex collection
115
+ # @see Graph#add_vertex_collection! if you need to know if the collection is already present
115
116
  # @return [VertexCollection] The newly created collection
116
117
  def add_vertex_collection(collection_name)
118
+ add_vertex_collection!(collection_name)
119
+ rescue Ashikawa::Core::VertexCollectionAlreadyPresent
120
+ vertex_collection(collection_name)
121
+ end
122
+
123
+ # Adds a vertex collection to this graph
124
+ #
125
+ # If the collection does not exist yet it will be created. Initially it will add it as an orphaned
126
+ # collection to the graph. If the collection is already present in the graph definition, either as
127
+ # an orphan or as part of an edge definition an error is raised.
128
+ #
129
+ # @param [String] collection_name The name of the vertex collection
130
+ # @raise [Ashikawa::Core::VertexCollectionAlreadyPresent] if the collection is already part of the graph
131
+ # @see Graph#add_vertex_collection if you want to silently ignore the exception
132
+ # @return [VertexCollection] The newly created collection
133
+ def add_vertex_collection!(collection_name)
117
134
  response = send_request("gharial/#@name/vertex", post: { collection: collection_name })
118
135
  parse_raw_graph(response['graph'])
119
136
  vertex_collection(collection_name)
@@ -159,11 +176,33 @@ module Ashikawa
159
176
 
160
177
  # Adds an edge definition to this Graph
161
178
  #
179
+ # If the edge definition doesn't exist it will be created, else it will just return the edge
180
+ # collection.
181
+ #
162
182
  # @param [Symbol] collection_name The name of the resulting edge collection
163
183
  # @param [Hash] directions The specification between which vertices the edges should be created
164
184
  # @option [Array<Symbol>] :from A list of collections names from which the edge directs
165
185
  # @option [Array<Symbol>] :to A list of collections names to which the edge directs
186
+ # @see Graph@add_edge_definition! if you need to know the edge definition was already present
187
+ # @return [EdgeCollection] The edge collection used be the definition
166
188
  def add_edge_definition(collection_name, directions)
189
+ add_edge_definition!(collection_name, directions)
190
+ rescue Ashikawa::Core::EdgeCollectionAlreadyPresent
191
+ edge_collection(collection_name)
192
+ end
193
+
194
+ # Adds an edge definition to this Graph
195
+ #
196
+ # If the edge definition doesn't exist it will be created, else it will raise an error.
197
+ #
198
+ # @param [Symbol] collection_name The name of the resulting edge collection
199
+ # @param [Hash] directions The specification between which vertices the edges should be created
200
+ # @option [Array<Symbol>] :from A list of collections names from which the edge directs
201
+ # @option [Array<Symbol>] :to A list of collections names to which the edge directs
202
+ # @raise Ashikawa::Core::EdgeCollectionAlreadyPresent if the edge definition is already defined
203
+ # @see Graph#add_edge_definition if you need an idempotent version of this
204
+ # @return [EdgeCollection] The edge collection used be the definition
205
+ def add_edge_definition!(collection_name, directions)
167
206
  create_options = {
168
207
  collection: collection_name,
169
208
  from: directions[:from],
@@ -2,7 +2,7 @@
2
2
  module Ashikawa
3
3
  module Core
4
4
  # Current version of Ashikawa::Core
5
- VERSION = '0.13.1'
5
+ VERSION = '0.14.0'
6
6
 
7
7
  # The lowest supported ArangoDB major version
8
8
  ARANGODB_MAJOR_VERSION = 2
@@ -58,6 +58,14 @@ describe 'Graphs' do
58
58
  expect(subject.edge_collections).to include visited
59
59
  end
60
60
 
61
+ it 'adding the same vertex collection should be idempotent' do
62
+ expect { subject.add_vertex_collection(:ponies) }.not_to raise_error
63
+ end
64
+
65
+ it 'adding the same edge definition should be idempotent' do
66
+ expect { subject.add_edge_definition(:friends_with, from: [:you], to: [:me]) }.not_to raise_error
67
+ end
68
+
61
69
  context 'connected vertices' do
62
70
  before :each do
63
71
  # There are only directed graphs
@@ -34,7 +34,7 @@ end
34
34
 
35
35
  def database_with_random_name
36
36
  # This results in a database that has a valid name according to:
37
- # https://www.arangodb.org/manuals/2/NamingConventions.html#DatabaseNames
37
+ # https://docs.arangodb.com/NamingConventions/DatabaseNames.html
38
38
  database_with_name("#{RANDOM_DB_PREFIX}#{rand.to_s[2, 10]}")
39
39
  end
40
40
 
@@ -7,8 +7,8 @@ NAME=ArangoDB-$VERSION
7
7
 
8
8
  if [ ! -d "$DIR/$NAME" ]; then
9
9
  # download ArangoDB
10
- echo "wget http://www.arangodb.org/repositories/travisCI/$NAME.tar.gz"
11
- wget http://www.arangodb.org/repositories/travisCI/$NAME.tar.gz
10
+ echo "wget http://www.arangodb.com/repositories/travisCI/$NAME.tar.gz"
11
+ wget http://www.arangodb.com/repositories/travisCI/$NAME.tar.gz
12
12
  echo "tar zxf $NAME.tar.gz"
13
13
  tar zvxf $NAME.tar.gz
14
14
  mv `find . -type d -name "ArangoDB-*"` $NAME
@@ -19,9 +19,14 @@ describe Ashikawa::Core::NoCollectionProvidedException do
19
19
  end
20
20
 
21
21
  describe Ashikawa::Core::ClientError do
22
- let(:error_message) { 'The client did not do what it should do' }
23
- subject { Ashikawa::Core::ClientError.new(error_message) }
24
- its(:to_s) { should be(error_message) }
22
+ subject { Ashikawa::Core::ClientError.new }
23
+ its(:to_s) { should eq('400 Bad Request') }
24
+
25
+ context 'with custom message' do
26
+ let(:error_message) { 'The client did not do what it should do' }
27
+ subject { Ashikawa::Core::ClientError.new(error_message) }
28
+ its(:to_s) { should eq(error_message) }
29
+ end
25
30
  end
26
31
 
27
32
  describe Ashikawa::Core::BadSyntax do
@@ -3,6 +3,8 @@ require 'unit/spec_helper'
3
3
  require 'ashikawa-core/graph'
4
4
  require 'ashikawa-core/document'
5
5
  require 'ashikawa-core/database'
6
+ require 'ashikawa-core/exceptions/client_error/vertex_collection_already_present'
7
+ require 'ashikawa-core/exceptions/client_error/edge_collection_already_present'
6
8
 
7
9
  describe Ashikawa::Core::Graph do
8
10
  let(:database) { instance_double('Ashikawa::Core::Database') }
@@ -184,6 +186,22 @@ describe Ashikawa::Core::Graph do
184
186
  it 'should return the newly created collection' do
185
187
  expect(subject.add_vertex_collection('books')).to eq new_vertex_collection
186
188
  end
189
+
190
+ context 'with an already present collection' do
191
+ before do
192
+ allow(database).to receive(:send_request)
193
+ .with('gharial/my_graph/vertex', post: { collection: 'books' })
194
+ .and_raise(Ashikawa::Core::VertexCollectionAlreadyPresent)
195
+ end
196
+
197
+ it 'should just return the vertex collection' do
198
+ expect(subject.add_vertex_collection('books')).to eq new_vertex_collection
199
+ end
200
+
201
+ it 'should re-raise the exception when called with a bang!' do
202
+ expect { subject.add_vertex_collection!('books') }.to raise_error(Ashikawa::Core::VertexCollectionAlreadyPresent)
203
+ end
204
+ end
187
205
  end
188
206
  end
189
207
 
@@ -264,6 +282,22 @@ describe Ashikawa::Core::Graph do
264
282
  it 'should return the edge collection' do
265
283
  expect(subject.add_edge_definition(:authorship, from: [:author], to: [:books])).to eq new_edge_collection
266
284
  end
285
+
286
+ context 'with an edge collection of the same name' do
287
+ before do
288
+ allow(database).to receive(:send_request)
289
+ .with('gharial/my_graph/edge', post: { collection: :authorship, from: [:author], to: [:books] })
290
+ .and_raise(Ashikawa::Core::EdgeCollectionAlreadyPresent)
291
+ end
292
+
293
+ it 'should just return the edge collection' do
294
+ expect(subject.add_edge_definition(:authorship, from: [:author], to: [:books])).to eq new_edge_collection
295
+ end
296
+
297
+ it 'should re-raise the exception when called with a bang!' do
298
+ expect { subject.add_edge_definition!(:authorship, from: [:author], to: [:books]) }.to raise_error(Ashikawa::Core::EdgeCollectionAlreadyPresent)
299
+ end
300
+ end
267
301
  end
268
302
  end
269
303
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ashikawa-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
- - moonglum
7
+ - Lucas Dohmen
8
+ - Dirk Breuer
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-10-24 00:00:00.000000000 Z
12
+ date: 2015-02-27 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: faraday
@@ -237,13 +238,15 @@ dependencies:
237
238
  description: Ashikawa Core is a wrapper around the ArangoDB REST API. It provides
238
239
  low level access and is intended to be used in ArangoDB ODMs and other tools.
239
240
  email:
240
- - me@moonglum.net
241
+ - lucas@arangodb.com
242
+ - dirk@arangodb.com
241
243
  executables: []
242
244
  extensions: []
243
245
  extra_rdoc_files: []
244
246
  files:
245
247
  - ".gitignore"
246
248
  - ".hound.yml"
249
+ - ".pullreview.yml"
247
250
  - ".rspec"
248
251
  - ".ruby-version"
249
252
  - ".travis.yml"
@@ -271,12 +274,14 @@ files:
271
274
  - lib/ashikawa-core/exceptions/client_error.rb
272
275
  - lib/ashikawa-core/exceptions/client_error/authentication_failed.rb
273
276
  - lib/ashikawa-core/exceptions/client_error/bad_syntax.rb
277
+ - lib/ashikawa-core/exceptions/client_error/edge_collection_already_present.rb
274
278
  - lib/ashikawa-core/exceptions/client_error/resource_not_found.rb
275
279
  - lib/ashikawa-core/exceptions/client_error/resource_not_found/collection_not_found.rb
276
280
  - lib/ashikawa-core/exceptions/client_error/resource_not_found/collection_not_in_graph.rb
277
281
  - lib/ashikawa-core/exceptions/client_error/resource_not_found/document_not_found.rb
278
282
  - lib/ashikawa-core/exceptions/client_error/resource_not_found/graph_not_found.rb
279
283
  - lib/ashikawa-core/exceptions/client_error/resource_not_found/index_not_found.rb
284
+ - lib/ashikawa-core/exceptions/client_error/vertex_collection_already_present.rb
280
285
  - lib/ashikawa-core/exceptions/no_collection_provided.rb
281
286
  - lib/ashikawa-core/exceptions/server_error.rb
282
287
  - lib/ashikawa-core/exceptions/server_error/json_error.rb
@@ -365,7 +370,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
365
370
  requirements:
366
371
  - ArangoDB, v2.1
367
372
  rubyforge_project: ashikawa-core
368
- rubygems_version: 2.2.2
373
+ rubygems_version: 2.4.5
369
374
  signing_key:
370
375
  specification_version: 4
371
376
  summary: Ashikawa Core is a wrapper around the ArangoDB REST API