ashikawa-core 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +49 -0
  5. data/Gemfile +3 -2
  6. data/Gemfile.devtools +14 -22
  7. data/Guardfile +3 -2
  8. data/README.md +37 -6
  9. data/Rakefile +2 -1
  10. data/ashikawa-core.gemspec +2 -2
  11. data/cache/Mac_applications +1 -0
  12. data/config/devtools.yml +5 -0
  13. data/config/flay.yml +1 -1
  14. data/config/flog.yml +1 -2
  15. data/config/reek.yml +1 -1
  16. data/config/rubocop.yml +23 -25
  17. data/lib/ashikawa-core.rb +6 -5
  18. data/lib/ashikawa-core/collection.rb +142 -165
  19. data/lib/ashikawa-core/configuration.rb +41 -2
  20. data/lib/ashikawa-core/connection.rb +17 -16
  21. data/lib/ashikawa-core/cursor.rb +18 -12
  22. data/lib/ashikawa-core/database.rb +69 -59
  23. data/lib/ashikawa-core/document.rb +22 -20
  24. data/lib/ashikawa-core/edge.rb +8 -6
  25. data/lib/ashikawa-core/exceptions/client_error.rb +1 -0
  26. data/lib/ashikawa-core/exceptions/client_error/authentication_failed.rb +25 -0
  27. data/lib/ashikawa-core/exceptions/client_error/bad_syntax.rb +3 -2
  28. data/lib/ashikawa-core/exceptions/client_error/resource_not_found.rb +3 -2
  29. data/lib/ashikawa-core/exceptions/client_error/resource_not_found/collection_not_found.rb +3 -2
  30. data/lib/ashikawa-core/exceptions/client_error/resource_not_found/document_not_found.rb +3 -2
  31. data/lib/ashikawa-core/exceptions/client_error/resource_not_found/index_not_found.rb +3 -2
  32. data/lib/ashikawa-core/exceptions/no_collection_provided.rb +1 -0
  33. data/lib/ashikawa-core/exceptions/server_error.rb +1 -0
  34. data/lib/ashikawa-core/exceptions/server_error/json_error.rb +3 -2
  35. data/lib/ashikawa-core/figure.rb +18 -17
  36. data/lib/ashikawa-core/index.rb +15 -5
  37. data/lib/ashikawa-core/key_options.rb +5 -4
  38. data/lib/ashikawa-core/query.rb +38 -27
  39. data/lib/ashikawa-core/request_preprocessor.rb +4 -3
  40. data/lib/ashikawa-core/response_preprocessor.rb +64 -24
  41. data/lib/ashikawa-core/status.rb +1 -0
  42. data/lib/ashikawa-core/transaction.rb +12 -11
  43. data/lib/ashikawa-core/version.rb +2 -1
  44. data/spec/acceptance/basic_spec.rb +117 -116
  45. data/spec/acceptance/index_spec.rb +18 -15
  46. data/spec/acceptance/query_spec.rb +61 -64
  47. data/spec/acceptance/spec_helper.rb +26 -3
  48. data/spec/acceptance/transactions_spec.rb +12 -16
  49. data/spec/setup/arangodb.sh +2 -2
  50. data/spec/unit/collection_spec.rb +224 -242
  51. data/spec/unit/configuration_spec.rb +64 -0
  52. data/spec/unit/connection_spec.rb +121 -111
  53. data/spec/unit/cursor_spec.rb +78 -65
  54. data/spec/unit/database_spec.rb +112 -163
  55. data/spec/unit/document_spec.rb +74 -70
  56. data/spec/unit/edge_spec.rb +45 -33
  57. data/spec/unit/exception_spec.rb +28 -38
  58. data/spec/unit/figure_spec.rb +44 -47
  59. data/spec/unit/index_spec.rb +27 -24
  60. data/spec/unit/key_options_spec.rb +19 -17
  61. data/spec/unit/query_spec.rb +186 -135
  62. data/spec/unit/spec_helper.rb +14 -3
  63. data/spec/unit/status_spec.rb +37 -37
  64. data/spec/unit/transaction_spec.rb +71 -74
  65. data/tasks/adjustments.rake +10 -34
  66. metadata +11 -13
  67. data/spec/acceptance/arango_helper.rb +0 -27
  68. data/spec/acceptance_auth/arango_helper.rb +0 -30
  69. data/spec/acceptance_auth/auth_spec.rb +0 -40
  70. data/spec/acceptance_auth/spec_helper.rb +0 -6
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'ashikawa-core/exceptions/client_error/resource_not_found/document_not_found'
2
3
  require 'equalizer'
3
4
 
@@ -13,7 +14,7 @@ module Ashikawa
13
14
  # @api public
14
15
  # @example Get the ID for a Document
15
16
  # document = Ashikawa::Core::Document.new(database, raw_document)
16
- # document.id # => "my_fancy_collection/2345678"
17
+ # document.id # => 'my_fancy_collection/2345678'
17
18
  attr_reader :id
18
19
 
19
20
  # The key of the document (No collection prefix)
@@ -22,7 +23,7 @@ module Ashikawa
22
23
  # @api public
23
24
  # @example Get the key for a Document
24
25
  # document = Ashikawa::Core::Document.new(database, raw_document)
25
- # document.key # => "2345678"
26
+ # document.key # => '2345678'
26
27
  attr_reader :key
27
28
 
28
29
  # The current revision of the document
@@ -38,11 +39,13 @@ module Ashikawa
38
39
  #
39
40
  # @param [Database] database
40
41
  # @param [Hash] raw_document
42
+ # @param [Hash] additional_data
41
43
  # @api public
42
44
  # @example Create a document
43
45
  # document = Ashikawa::Core::Document.new(database, raw_document)
44
- def initialize(database, raw_document)
46
+ def initialize(database, raw_document, additional_data = {})
45
47
  @database = database
48
+ raw_document.merge!(clean_up_additional_data(additional_data))
46
49
  parse_raw_document(raw_document)
47
50
  end
48
51
 
@@ -79,7 +82,7 @@ module Ashikawa
79
82
  # document.delete
80
83
  def delete
81
84
  check_if_persisted!
82
- send_request_for_document(:delete => {})
85
+ send_request_for_document(delete: {})
83
86
  end
84
87
 
85
88
  # Update the value of an attribute (Does not write to database)
@@ -102,24 +105,11 @@ module Ashikawa
102
105
  # @api public
103
106
  # @example Get the hash representation of a document
104
107
  # document = Ashikawa::Core::Document.new(database, raw_document)
105
- # document.hash #=> { :name => "Lebowski", :occupation => "Not occupied" }
108
+ # document.hash #=> { :name => 'Lebowski", :occupation => "Not occupied' }
106
109
  def hash
107
110
  @content
108
111
  end
109
112
 
110
- # Convert the document into a hash
111
- #
112
- # @return [Hash]
113
- # @api public
114
- # @deprecated Use {#hash} instead.
115
- # @example Get the hash representation of a document
116
- # document = Ashikawa::Core::Document.new(database, raw_document)
117
- # document.to_hash #=> { :name => "Lebowski", :occupation => "Not occupied" }
118
- def to_hash
119
- warn "`to_hash` is deprecated, please use `hash`"
120
- hash
121
- end
122
-
123
113
  # Save the changes to the database
124
114
  #
125
115
  # @return [Hash] parsed JSON response from the server
@@ -130,7 +120,7 @@ module Ashikawa
130
120
  # document.save
131
121
  def save
132
122
  check_if_persisted!
133
- send_request_for_document(:put => @content)
123
+ send_request_for_document(put: @content)
134
124
  end
135
125
 
136
126
  # Get a fresh version of this document from the database
@@ -155,7 +145,7 @@ module Ashikawa
155
145
  @id = raw_document['_id'] || :not_persisted
156
146
  @key = raw_document['_key']
157
147
  @revision = raw_document['_rev'] || :not_persisted
158
- @content = raw_document.delete_if { |key, value| key.start_with?("_") }
148
+ @content = raw_document.delete_if { |key, value| key.start_with?('_') }
159
149
  self
160
150
  end
161
151
 
@@ -167,6 +157,18 @@ module Ashikawa
167
157
  def send_request_for_document(opts = {})
168
158
  @database.send_request("document/#{@id}", opts)
169
159
  end
160
+
161
+ # Clean up the raw data hash to have string keys
162
+ #
163
+ # @param [Hash] raw_data
164
+ # @return [Hash] Cleaned up hash
165
+ # @api private
166
+ def clean_up_additional_data(raw_data)
167
+ raw_data.reduce({}) do |result, (key, value)|
168
+ result[key.to_s] = value
169
+ result
170
+ end
171
+ end
170
172
  end
171
173
  end
172
174
  end
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'ashikawa-core/document'
2
3
  require 'equalizer'
3
4
 
@@ -13,7 +14,7 @@ module Ashikawa
13
14
  # @api public
14
15
  # @example Get the ID for the 'from' Document
15
16
  # document = Ashikawa::Core::Edge.new(database, raw_document)
16
- # document.from_id # => "my_fancy_collection/2345678"
17
+ # document.from_id # => 'my_fancy_collection/2345678'
17
18
  attr_reader :from_id
18
19
 
19
20
  # The ID of the 'to' document
@@ -22,20 +23,21 @@ module Ashikawa
22
23
  # @api public
23
24
  # @example Get the ID for the 'to' Document
24
25
  # document = Ashikawa::Core::Edge.new(database, raw_document)
25
- # document.to_id # => "my_fancy_collection/2345678"
26
+ # document.to_id # => 'my_fancy_collection/2345678'
26
27
  attr_reader :to_id
27
28
 
28
29
  # Initialize an Edge with the database and raw data
29
30
  #
30
31
  # @param [Database] database
31
32
  # @param [Hash] raw_edge
33
+ # @param [Hash] additional_data
32
34
  # @api public
33
35
  # @example Create an Edge
34
36
  # document = Ashikawa::Core::Edge.new(database, raw_edge)
35
- def initialize(database, raw_edge)
36
- @from_id = raw_edge["_from"]
37
- @to_id = raw_edge["_to"]
38
- super(database, raw_edge)
37
+ def initialize(database, raw_edge, additional_data = {})
38
+ @from_id = raw_edge['_from']
39
+ @to_id = raw_edge['_to']
40
+ super(database, raw_edge, additional_data)
39
41
  end
40
42
 
41
43
  protected
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Ashikawa
2
3
  module Core
3
4
  # The client had an error in the request
@@ -0,0 +1,25 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ashikawa-core/exceptions/client_error.rb'
3
+
4
+ module Ashikawa
5
+ module Core
6
+ # This exception is thrown when the client is not authorized
7
+ class AuthenticationFailed < ClientError
8
+ # Create a new authentication failure
9
+ #
10
+ # @return RuntimeError
11
+ # @api private
12
+ def initialize
13
+ super(401)
14
+ end
15
+
16
+ # String representation of the exception
17
+ #
18
+ # @return String
19
+ # @api private
20
+ def to_s
21
+ 'Status 401: Authentication failed'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,5 @@
1
- require "ashikawa-core/exceptions/client_error.rb"
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ashikawa-core/exceptions/client_error.rb'
2
3
 
3
4
  module Ashikawa
4
5
  module Core
@@ -17,7 +18,7 @@ module Ashikawa
17
18
  # @return String
18
19
  # @api private
19
20
  def to_s
20
- "Status 400: The syntax of the request was bad"
21
+ 'Status 400: The syntax of the request was bad'
21
22
  end
22
23
  end
23
24
  end
@@ -1,4 +1,5 @@
1
- require "ashikawa-core/exceptions/client_error.rb"
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ashikawa-core/exceptions/client_error.rb'
2
3
 
3
4
  module Ashikawa
4
5
  module Core
@@ -18,7 +19,7 @@ module Ashikawa
18
19
  # @return String
19
20
  # @api private
20
21
  def to_s
21
- "Status 404: The Resource you requested was not found on the server"
22
+ 'Status 404: The Resource you requested was not found on the server'
22
23
  end
23
24
  end
24
25
  end
@@ -1,4 +1,5 @@
1
- require "ashikawa-core/exceptions/client_error/resource_not_found"
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ashikawa-core/exceptions/client_error/resource_not_found'
2
3
 
3
4
  module Ashikawa
4
5
  module Core
@@ -10,7 +11,7 @@ module Ashikawa
10
11
  # @return String
11
12
  # @api private
12
13
  def to_s
13
- "You requested a collection from the server that does not exist"
14
+ 'You requested a collection from the server that does not exist'
14
15
  end
15
16
  end
16
17
  end
@@ -1,4 +1,5 @@
1
- require "ashikawa-core/exceptions/client_error/resource_not_found"
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ashikawa-core/exceptions/client_error/resource_not_found'
2
3
 
3
4
  module Ashikawa
4
5
  module Core
@@ -10,7 +11,7 @@ module Ashikawa
10
11
  # @return String
11
12
  # @api private
12
13
  def to_s
13
- "You requested a document from the server that does not exist"
14
+ 'You requested a document from the server that does not exist'
14
15
  end
15
16
  end
16
17
  end
@@ -1,4 +1,5 @@
1
- require "ashikawa-core/exceptions/client_error/resource_not_found"
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ashikawa-core/exceptions/client_error/resource_not_found'
2
3
 
3
4
  module Ashikawa
4
5
  module Core
@@ -10,7 +11,7 @@ module Ashikawa
10
11
  # @return String
11
12
  # @api private
12
13
  def to_s
13
- "You requested an index from the server that does not exist"
14
+ 'You requested an index from the server that does not exist'
14
15
  end
15
16
  end
16
17
  end
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Ashikawa
2
3
  module Core
3
4
  # This Exception is thrown when a Query object should execute a simple query
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Ashikawa
2
3
  module Core
3
4
  # The server had an error during the request
@@ -1,4 +1,5 @@
1
- require "ashikawa-core/exceptions/server_error"
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ashikawa-core/exceptions/server_error'
2
3
 
3
4
  module Ashikawa
4
5
  module Core
@@ -18,7 +19,7 @@ module Ashikawa
18
19
  # @return String
19
20
  # @api private
20
21
  def to_s
21
- "Either the JSON from the server was malformed or the content type incorrect"
22
+ 'Either the JSON from the server was malformed or the content type incorrect'
22
23
  end
23
24
  end
24
25
  end
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Ashikawa
2
3
  module Core
3
4
  # Wrapper around figures of a collection
@@ -9,12 +10,12 @@ module Ashikawa
9
10
  # @example Create a new figure from a raw figure
10
11
  # figure = Ashikawa::Core::Figure.new(raw_figure)
11
12
  def initialize(raw_figure)
12
- @datafiles = raw_figure["datafiles"]
13
- @alive = raw_figure["alive"]
14
- @dead = raw_figure["dead"]
15
- @shapes = raw_figure["shapes"]
16
- @journals = raw_figure["journals"]
17
- @attributes = raw_figure["attributes"]
13
+ @datafiles = raw_figure['datafiles']
14
+ @alive = raw_figure['alive']
15
+ @dead = raw_figure['dead']
16
+ @shapes = raw_figure['shapes']
17
+ @journals = raw_figure['journals']
18
+ @attributes = raw_figure['attributes']
18
19
  end
19
20
 
20
21
  # The number of active datafiles
@@ -25,7 +26,7 @@ module Ashikawa
25
26
  # figure = Ashikawa::Core::Figure.new(raw_figure)
26
27
  # figure.datafiles_count #=> 1337
27
28
  def datafiles_count
28
- @datafiles["count"]
29
+ @datafiles['count']
29
30
  end
30
31
 
31
32
  # The file size of datafiles
@@ -36,7 +37,7 @@ module Ashikawa
36
37
  # figure = Ashikawa::Core::Figure.new(raw_figure)
37
38
  # figure.datafile_size #=> 1337
38
39
  def datafiles_file_size
39
- @datafiles["fileSize"]
40
+ @datafiles['fileSize']
40
41
  end
41
42
 
42
43
  # The total size in bytes used by all living documents
@@ -47,7 +48,7 @@ module Ashikawa
47
48
  # figure = Ashikawa::Core::Figure.new(raw_figure)
48
49
  # figure.alive_size #=> 1337
49
50
  def alive_size
50
- @alive["size"]
51
+ @alive['size']
51
52
  end
52
53
 
53
54
  # The number of living documents
@@ -58,7 +59,7 @@ module Ashikawa
58
59
  # figure = Ashikawa::Core::Figure.new(raw_figure)
59
60
  # figure.alive_count #=> 1337
60
61
  def alive_count
61
- @alive["count"]
62
+ @alive['count']
62
63
  end
63
64
 
64
65
  # The total size in bytes used by all dead documents
@@ -69,7 +70,7 @@ module Ashikawa
69
70
  # figure = Ashikawa::Core::Figure.new(raw_figure)
70
71
  # figure.dead_size #=> 1337
71
72
  def dead_size
72
- @dead["size"]
73
+ @dead['size']
73
74
  end
74
75
 
75
76
  # The number of dead documents
@@ -80,7 +81,7 @@ module Ashikawa
80
81
  # figure = Ashikawa::Core::Figure.new(raw_figure)
81
82
  # figure.dead_count #=> 1337
82
83
  def dead_count
83
- @dead["count"]
84
+ @dead['count']
84
85
  end
85
86
 
86
87
  # The total number of shapes used in the collection
@@ -91,7 +92,7 @@ module Ashikawa
91
92
  # figure = Ashikawa::Core::Figure.new(raw_figure)
92
93
  # figure.shapes_count #=> 1337
93
94
  def shapes_count
94
- @shapes["count"]
95
+ @shapes['count']
95
96
  end
96
97
 
97
98
  # The number of deletion markers
@@ -102,7 +103,7 @@ module Ashikawa
102
103
  # figure = Ashikawa::Core::Figure.new(raw_figure)
103
104
  # figure.dead_deletion #=> 1337
104
105
  def dead_deletion
105
- @dead["deletion"]
106
+ @dead['deletion']
106
107
  end
107
108
 
108
109
  # The number of journals
@@ -113,7 +114,7 @@ module Ashikawa
113
114
  # figure = Ashikawa::Core::Figure.new(raw_figure)
114
115
  # figure.journal_count #=> 1337
115
116
  def journals_count
116
- @journals["count"]
117
+ @journals['count']
117
118
  end
118
119
 
119
120
  # The file size of journals
@@ -124,7 +125,7 @@ module Ashikawa
124
125
  # figure = Ashikawa::Core::Figure.new(raw_figure)
125
126
  # figure.journal_size #=> 1337
126
127
  def journals_file_size
127
- @journals["fileSize"]
128
+ @journals['fileSize']
128
129
  end
129
130
 
130
131
  # Number of different attributes that are or have been used in the collection
@@ -135,7 +136,7 @@ module Ashikawa
135
136
  # figure = Ashikawa::Core::Figure.new(raw_figure)
136
137
  # figure.attributes_count #=> 12
137
138
  def attributes_count
138
- @attributes["count"]
139
+ @attributes['count']
139
140
  end
140
141
  end
141
142
  end
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'equalizer'
2
3
 
3
4
  module Ashikawa
@@ -63,7 +64,7 @@ module Ashikawa
63
64
  # index = Ashikawa::Core::Index.new(collection, raw_index)
64
65
  # index.delete
65
66
  def delete
66
- @collection.send_request("index/#{@id}", :delete => {})
67
+ @collection.send_request("index/#{@id}", delete: {})
67
68
  end
68
69
 
69
70
  private
@@ -74,12 +75,21 @@ module Ashikawa
74
75
  # @return self
75
76
  # @api private
76
77
  def parse_raw_index(raw_index)
77
- @id = raw_index["id"]
78
- @on = raw_index["fields"].map { |field| field.to_sym } if raw_index.has_key?("fields")
79
- @type = raw_index["type"].to_sym if raw_index.has_key?("type")
80
- @unique = raw_index["unique"]
78
+ @id = raw_index['id']
79
+ @on = convert_to_symbols(raw_index['fields']) if raw_index.key?('fields')
80
+ @type = raw_index['type'].to_sym if raw_index.key?('type')
81
+ @unique = raw_index['unique']
81
82
  self
82
83
  end
84
+
85
+ # Convert all elements of an array to symbols
86
+ #
87
+ # @param [Array] arr
88
+ # @return Array
89
+ # @api private
90
+ def convert_to_symbols(arr)
91
+ arr.map { |field| field.to_sym }
92
+ end
83
93
  end
84
94
  end
85
95
  end