ashikawa-core 0.9.0 → 0.10.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +7 -7
  4. data/CHANGELOG.md +25 -0
  5. data/CONTRIBUTING.md +4 -4
  6. data/Gemfile.devtools +32 -16
  7. data/README.md +9 -11
  8. data/Rakefile +3 -0
  9. data/ashikawa-core.gemspec +7 -5
  10. data/config/flay.yml +2 -2
  11. data/config/flog.yml +2 -1
  12. data/config/mutant.yml +14 -1
  13. data/config/reek.yml +9 -4
  14. data/config/rubocop.yml +14 -14
  15. data/lib/ashikawa-core/collection.rb +10 -6
  16. data/lib/ashikawa-core/configuration.rb +10 -5
  17. data/lib/ashikawa-core/connection.rb +30 -21
  18. data/lib/ashikawa-core/cursor.rb +2 -3
  19. data/lib/ashikawa-core/database.rb +12 -35
  20. data/lib/ashikawa-core/document.rb +3 -4
  21. data/lib/ashikawa-core/edge.rb +5 -5
  22. data/lib/ashikawa-core/error_response.rb +108 -0
  23. data/lib/ashikawa-core/index.rb +4 -14
  24. data/lib/ashikawa-core/query.rb +1 -1
  25. data/lib/ashikawa-core/transaction.rb +1 -16
  26. data/lib/ashikawa-core/version.rb +1 -1
  27. data/spec/acceptance/basic_spec.rb +9 -6
  28. data/spec/acceptance/spec_helper.rb +5 -4
  29. data/spec/setup/arangodb.sh +12 -17
  30. data/spec/unit/collection_spec.rb +60 -18
  31. data/spec/unit/configuration_spec.rb +35 -4
  32. data/spec/unit/connection_spec.rb +23 -65
  33. data/spec/unit/cursor_spec.rb +2 -2
  34. data/spec/unit/database_spec.rb +16 -28
  35. data/spec/unit/document_spec.rb +3 -3
  36. data/spec/unit/edge_spec.rb +1 -1
  37. data/spec/unit/index_spec.rb +1 -1
  38. data/spec/unit/query_spec.rb +1 -1
  39. data/spec/unit/spec_helper.rb +3 -2
  40. data/tasks/adjustments.rake +0 -14
  41. metadata +26 -13
  42. data/lib/ashikawa-core/request_preprocessor.rb +0 -50
  43. data/lib/ashikawa-core/response_preprocessor.rb +0 -160
@@ -11,7 +11,7 @@ describe Ashikawa::Core::Document do
11
11
  let(:first_name) { double }
12
12
  let(:last_name) { double }
13
13
  let(:more_info) { double }
14
- let(:delete_payload) {{ delete: {} }}
14
+ let(:delete_payload) { { delete: {} } }
15
15
  let(:raw_data) do
16
16
  {
17
17
  '_id' => id,
@@ -69,8 +69,8 @@ describe Ashikawa::Core::Document do
69
69
 
70
70
  its(['first_name']) { should be(first_name) }
71
71
  its(['no_name']) { should be_nil }
72
- its(:hash) { should be_instance_of Hash }
73
- its(:hash) { should include('first_name' => first_name) }
72
+ its(:to_h) { should be_instance_of Hash }
73
+ its(:to_h) { should include('first_name' => first_name) }
74
74
 
75
75
  it 'should be deletable' do
76
76
  expect(database).to receive(:send_request).with(path, delete_payload)
@@ -58,7 +58,7 @@ describe Ashikawa::Core::Edge do
58
58
 
59
59
  describe 'initializing edge with additional data' do
60
60
  let(:more_info) { double }
61
- let(:additional_data) {{ more_info: more_info }}
61
+ let(:additional_data) { { more_info: more_info } }
62
62
  subject { Ashikawa::Core::Edge.new(database, raw_data, additional_data) }
63
63
 
64
64
  its(['more_info']) { should eq(more_info) }
@@ -6,7 +6,7 @@ describe Ashikawa::Core::Index do
6
6
  let(:collection) { double }
7
7
  let(:id) { '167137465/168054969' }
8
8
  let(:path) { 'index/167137465/168054969' }
9
- let(:delete_payload) {{ delete: {} }}
9
+ let(:delete_payload) { { delete: {} } }
10
10
  let(:type_as_sym) { double }
11
11
  let(:type) { double(to_sym: type_as_sym) }
12
12
  let(:field_as_sym) { double }
@@ -64,7 +64,7 @@ describe Ashikawa::Core::Query do
64
64
  end
65
65
 
66
66
  describe 'all by example' do
67
- let(:example) {{ hello: 'world' }}
67
+ let(:example) { { hello: 'world' } }
68
68
  let(:response) { server_response('simple-queries/example') }
69
69
  let(:limit) { double }
70
70
  let(:skip) { double }
@@ -13,7 +13,7 @@ RSpec.configure do |config|
13
13
  end
14
14
 
15
15
  # Do not run SimpleCov in Guard
16
- unless defined?(Guard)
16
+ if ENV['COVERAGE'] == 'true'
17
17
  require 'simplecov'
18
18
  require 'coveralls'
19
19
 
@@ -30,8 +30,9 @@ unless defined?(Guard)
30
30
  end
31
31
  end
32
32
 
33
- # Helper to simulate Server Responses. Parses the fixtures in the spec folder
34
33
  require 'json'
34
+
35
+ # Helper to simulate Server Responses. Parses the fixtures in the spec folder
35
36
  def server_response(path)
36
37
  JSON.parse(File.readlines("spec/fixtures/#{path}.json").join)
37
38
  end
@@ -15,17 +15,3 @@ namespace :spec do
15
15
  spec.pattern = 'spec/acceptance/*_spec.rb'
16
16
  end
17
17
  end
18
-
19
- ## Metrics
20
- # Differences to Devtools:
21
- # * Do not run mutant yet
22
-
23
- Rake::Task['ci'].clear
24
-
25
- desc 'Run all metrics and specs'
26
- task ci: %w[
27
- spec
28
- ci:metrics
29
- ]
30
-
31
- task default: :ci
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ashikawa-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - moonglum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-08 00:00:00.000000000 Z
11
+ date: 2014-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.6
19
+ version: 0.8.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.6
26
+ version: 0.8.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: json
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ~>
32
46
  - !ruby/object:Gem::Version
33
- version: 1.8.0
47
+ version: 1.8.1
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ~>
39
53
  - !ruby/object:Gem::Version
40
- version: 1.8.0
54
+ version: 1.8.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: null_logger
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +72,14 @@ dependencies:
58
72
  requirements:
59
73
  - - ~>
60
74
  - !ruby/object:Gem::Version
61
- version: 0.0.5
75
+ version: 0.0.8
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ~>
67
81
  - !ruby/object:Gem::Version
68
- version: 0.0.5
82
+ version: 0.0.8
69
83
  description: Ashikawa Core is a wrapper around the ArangoDB REST API. It provides
70
84
  low level access and is intended to be used in ArangoDB ODMs and other tools.
71
85
  email:
@@ -104,6 +118,7 @@ files:
104
118
  - lib/ashikawa-core/database.rb
105
119
  - lib/ashikawa-core/document.rb
106
120
  - lib/ashikawa-core/edge.rb
121
+ - lib/ashikawa-core/error_response.rb
107
122
  - lib/ashikawa-core/exceptions/client_error.rb
108
123
  - lib/ashikawa-core/exceptions/client_error/authentication_failed.rb
109
124
  - lib/ashikawa-core/exceptions/client_error/bad_syntax.rb
@@ -118,8 +133,6 @@ files:
118
133
  - lib/ashikawa-core/index.rb
119
134
  - lib/ashikawa-core/key_options.rb
120
135
  - lib/ashikawa-core/query.rb
121
- - lib/ashikawa-core/request_preprocessor.rb
122
- - lib/ashikawa-core/response_preprocessor.rb
123
136
  - lib/ashikawa-core/status.rb
124
137
  - lib/ashikawa-core/transaction.rb
125
138
  - lib/ashikawa-core/version.rb
@@ -182,16 +195,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
195
  requirements:
183
196
  - - '>='
184
197
  - !ruby/object:Gem::Version
185
- version: 1.9.2
198
+ version: 1.9.3
186
199
  required_rubygems_version: !ruby/object:Gem::Requirement
187
200
  requirements:
188
201
  - - '>='
189
202
  - !ruby/object:Gem::Version
190
203
  version: '0'
191
204
  requirements:
192
- - ArangoDB, v1.4
205
+ - ArangoDB, v1.4 or v2.0
193
206
  rubyforge_project: ashikawa-core
194
- rubygems_version: 2.1.1
207
+ rubygems_version: 2.2.2
195
208
  signing_key:
196
209
  specification_version: 4
197
210
  summary: Ashikawa Core is a wrapper around the ArangoDB REST API
@@ -1,50 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'faraday'
3
- require 'json'
4
-
5
- module Ashikawa
6
- module Core
7
- # Preprocessor for Faraday Requests
8
- class RequestPreprocessor < Faraday::Middleware
9
- # Create a new Request Preprocessor
10
- #
11
- # @param [Object] app Faraday internal
12
- # @param [Object] logger The object you want to log to
13
- # @return [RequestPreprocessor]
14
- # @api private
15
- def initialize(app, logger)
16
- @app = app
17
- @logger = logger
18
- end
19
-
20
- # Process a Request
21
- #
22
- # @param [Hash] env Environment info
23
- # @return [Object]
24
- # @api private
25
- def call(env)
26
- body = env[:body]
27
- env[:body] = JSON.generate(body) if body
28
- log(env[:method], env[:url], body)
29
- @app.call(env)
30
- end
31
-
32
- private
33
-
34
- # Log a Request
35
- #
36
- # @param [Symbol] method
37
- # @param [String] url
38
- # @param [String] body
39
- # @return [nil]
40
- # @api private
41
- def log(method, url, body)
42
- @logger.info("#{method.upcase} #{url} #{body}")
43
- nil
44
- end
45
- end
46
-
47
- Faraday.register_middleware :request,
48
- ashikawa_request: -> { RequestPreprocessor}
49
- end
50
- end
@@ -1,160 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'faraday'
3
- require 'json'
4
- require 'ashikawa-core/exceptions/client_error'
5
- require 'ashikawa-core/exceptions/client_error/resource_not_found'
6
- require 'ashikawa-core/exceptions/client_error/resource_not_found/index_not_found'
7
- require 'ashikawa-core/exceptions/client_error/resource_not_found/document_not_found'
8
- require 'ashikawa-core/exceptions/client_error/resource_not_found/collection_not_found'
9
- require 'ashikawa-core/exceptions/client_error/bad_syntax'
10
- require 'ashikawa-core/exceptions/client_error/authentication_failed'
11
- require 'ashikawa-core/exceptions/server_error'
12
- require 'ashikawa-core/exceptions/server_error/json_error'
13
-
14
- module Ashikawa
15
- module Core
16
- # Preprocessor for Faraday Requests
17
- class ResponsePreprocessor < Faraday::Middleware
18
- BadSyntaxStatus = 400
19
- AuthenticationFailed = 401
20
- ResourceNotFoundError = 404
21
- ClientErrorStatuses = 405...499
22
- ServerErrorStatuses = 500...599
23
-
24
- # Create a new Response Preprocessor
25
- #
26
- # @param [Object] app Faraday internal
27
- # @param [Object] logger The object you want to log to
28
- # @return [ResponsePreprocessor]
29
- # @api private
30
- def initialize(app, logger)
31
- @app = app
32
- @logger = logger
33
- end
34
-
35
- # Process a Response
36
- #
37
- # @param [Hash] env Environment info
38
- # @return [Object]
39
- # @api private
40
- def call(env)
41
- @app.call(env).on_complete do
42
- log(env)
43
- handle_status(env)
44
- env[:body] = parse_json(env)
45
- end
46
- end
47
-
48
- private
49
-
50
- # Raise the fitting ResourceNotFoundException
51
- #
52
- # @raise [DocumentNotFoundException, CollectionNotFoundException, IndexNotFoundException]
53
- # @return nil
54
- # @api private
55
- def resource_not_found_for(env)
56
- raise case env[:url].path
57
- when %r{\A(/_db/[^/]+)?/_api/document} then Ashikawa::Core::DocumentNotFoundException
58
- when %r{\A(/_db/[^/]+)?/_api/collection} then Ashikawa::Core::CollectionNotFoundException
59
- when %r{\A(/_db/[^/]+)?/_api/index} then Ashikawa::Core::IndexNotFoundException
60
- else Ashikawa::Core::ResourceNotFound
61
- end
62
- end
63
-
64
- # Raise a Bad Syntax Error
65
- #
66
- # @raise [BadSyntax]
67
- # @return nil
68
- # @api private
69
- def bad_syntax
70
- raise Ashikawa::Core::BadSyntax
71
- end
72
-
73
- # Raise an Authentication Failed Error
74
- #
75
- # @raise [AuthenticationFailed]
76
- # @return nil
77
- # @api private
78
- def authentication_failed
79
- raise Ashikawa::Core::AuthenticationFailed
80
- end
81
-
82
- # Raise a Client Error for a given body
83
- #
84
- # @raise [ClientError]
85
- # @return nil
86
- # @api private
87
- def client_error_status_for(body)
88
- raise Ashikawa::Core::ClientError, error(body)
89
- end
90
-
91
- # Raise a Server Error for a given body
92
- #
93
- # @raise [ServerError]
94
- # @return nil
95
- # @api private
96
- def server_error_status_for(body)
97
- raise Ashikawa::Core::ServerError, error(body)
98
- end
99
-
100
- # Parse the JSON
101
- #
102
- # @param [Hash] env Environment info
103
- # @return [Hash] The parsed body
104
- # @api private
105
- def parse_json(env)
106
- fail JSON::ParserError unless json_content_type?(env[:response_headers]['content-type'])
107
- JSON.parse(env[:body])
108
- rescue JSON::ParserError
109
- raise Ashikawa::Core::JsonError
110
- end
111
-
112
- # Check if the Content Type is JSON
113
- #
114
- # @param [String] content_type
115
- # @return [Boolean]
116
- # @api private
117
- def json_content_type?(content_type)
118
- content_type == 'application/json; charset=utf-8'
119
- end
120
-
121
- # Handle the status code
122
- #
123
- # @param [Hash] env Environment info
124
- # @return [nil]
125
- # @api private
126
- def handle_status(env)
127
- case env[:status]
128
- when BadSyntaxStatus then bad_syntax
129
- when AuthenticationFailed then authentication_failed
130
- when ResourceNotFoundError then resource_not_found_for(env)
131
- when ClientErrorStatuses then client_error_status_for(env[:body])
132
- when ServerErrorStatuses then server_error_status_for(env[:body])
133
- end
134
- end
135
-
136
- # Log a Request
137
- #
138
- # @param [Hash] env Environment info
139
- # @return [nil]
140
- # @api private
141
- def log(env)
142
- @logger.info("#{env[:status]} #{env[:body]}")
143
- nil
144
- end
145
-
146
- # Read the error message for the request
147
- #
148
- # @param [String] The raw body of the request
149
- # @return [String] The formatted error message
150
- # @api private
151
- def error(body)
152
- parsed_body = JSON.parse(body)
153
- "#{parsed_body['errorNum']}: #{parsed_body["errorMessage"]}"
154
- end
155
- end
156
-
157
- Faraday.register_middleware :response,
158
- ashikawa_response: -> { ResponsePreprocessor}
159
- end
160
- end