ashikawa-core 0.11.0 → 0.12.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: 243fdb95bc1ad7691bc5129b1dce1f85ad929792
4
- data.tar.gz: e5bc4fda8b7d97e6bf90cf8570227afaff1b9128
3
+ metadata.gz: 0188e3f9d7f519dd6219ecf2cf7f54d57e2318b6
4
+ data.tar.gz: a8b0deb872c8771186b23861d7aacf264b16facf
5
5
  SHA512:
6
- metadata.gz: 31d2dcb8dc2b0ad4c431181cac8cc22daf224215791406dca9d81e4f78f472187e156a4b9e7f36a38a1bc4f9d9f5dfc7bfc806a2c24def3265eefb1d455e6362
7
- data.tar.gz: d0bc42d3059d787ea3747c279c0c522d4bcb4558cae5978529e33945726ba3f8f7260c90a447f6a97700f7d19b449d9bd1da03a805426b87ac0223c90cd2ce0d
6
+ metadata.gz: dd134061b8cfad2f9aee15e9f9fed43b77c8f2bbebf9c19e4932ad53786e66b9a8ce1e42a7c1b593aee4be1086b4a7b90c412cc7ec310869891ee26892c24a58
7
+ data.tar.gz: 094089ba8bcfdc3776722d3c8aff6a4e21f7c8fe72b353cdfa97a03baf0c79f4742c30740092efa67e1db5f698cb4ac5697a7b8f7609bb2b12fb7907236d6a16
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /Gemfile.lock
7
7
  /pkg/*
8
8
  /report/*
9
+ /log/*.log
9
10
  /measurements/*
10
11
  /coverage
11
12
  /.rbx
@@ -8,7 +8,7 @@ rvm:
8
8
  - jruby-1.7.12
9
9
  - rbx-2.2.6
10
10
  env:
11
- - ARANGODB_DISABLE_AUTHENTIFICATION=false VERSION=2.0
11
+ - ARANGODB_DISABLE_AUTHENTIFICATION=false VERSION=2.1
12
12
  matrix:
13
13
  allow_failures:
14
14
  - rvm: 2.1.0
@@ -1,3 +1,21 @@
1
+ # Version 0.12.0
2
+
3
+ **Codename: V for Verifying**
4
+
5
+ * Support for ArangoDB 2.1
6
+ * Accept single attributes in add_index (#120)
7
+ * JSON is no longer a runtime dependency but a development dependency (#118)
8
+ * Make database name explicit (#117)
9
+ * **Breaking Change:** Removed 'prima donna methods'
10
+ * Using a less verbose logging middleware (#124)
11
+ * Refactored the internal connection creation to support better external configuration (#126)
12
+ * Development only:
13
+ * Using Rspec 3.0
14
+ * Switched to verifying doubles
15
+ * New Contributors
16
+ * Ujjwal Thaakar (@ujjwalt)
17
+ * René Föhring (@rrrene)
18
+
1
19
  # Version 0.11
2
20
 
3
21
  **Codename: R3C0NF1GUR3D**
data/Gemfile CHANGED
@@ -3,6 +3,4 @@ source 'https://rubygems.org'
3
3
 
4
4
  gemspec
5
5
 
6
- %w( core mocks expectations support its ).each do |name|
7
- gem "rspec-#{name}", github: "rspec/rspec-#{name}"
8
- end
6
+ gem 'rspec-its', git: 'https://github.com/rspec/rspec-its.git'
data/README.md CHANGED
@@ -6,10 +6,11 @@
6
6
  | Documentation | [RubyDoc](http://www.rubydoc.info/gems/ashikawa-core)
7
7
  | CI | [![Build Status](http://img.shields.io/travis/triAGENS/ashikawa-core.svg)](http://travis-ci.org/triAGENS/ashikawa-core)
8
8
  | Code Metrics | [![Code Climate](http://img.shields.io/codeclimate/github/triAGENS/ashikawa-core.svg)](https://codeclimate.com/github/triAGENS/ashikawa-core) [![Code Climate Coverage](http://img.shields.io/codeclimate/coverage/github/triAGENS/ashikawa-core.svg)](https://codeclimate.com/github/triAGENS/ashikawa-core)
9
+ | Inline docs | [![Inline docs](http://inch-pages.github.io/github/triAGENS/ashikawa-core.svg)](http://inch-pages.github.io/github/triAGENS/ashikawa-core)
9
10
  | Gem Version | [![Gem Version](http://img.shields.io/gem/v/ashikawa-core.svg)](http://rubygems.org/gems/ashikawa-core)
10
11
  | Dependencies | [![Dependency Status](http://img.shields.io/gemnasium/triAGENS/ashikawa-core.svg)](https://gemnasium.com/triAGENS/ashikawa-core)
11
12
 
12
- 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.0**.
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.1**.
13
14
 
14
15
  All tests run on Travis CI for the following versions of Ruby:
15
16
 
@@ -26,7 +27,7 @@ gem install ashikawa-core
26
27
  or, when using bundler:
27
28
 
28
29
  ```ruby
29
- gem "ashikawa-core", "~> 0.11"
30
+ gem "ashikawa-core"
30
31
  ```
31
32
 
32
33
  ## How to Setup a Connection?
@@ -43,7 +44,8 @@ If you want to access the `my_db` database of your ArangoDB instance (and not th
43
44
 
44
45
  ```ruby
45
46
  database = Ashikawa::Core::Database.new do |config|
46
- config.url = "http://localhost:8529/_db/my_db"
47
+ config.url = "http://localhost:8529"
48
+ configl.database_name = 'my_db'
47
49
  config.username = "lebowski"
48
50
  config.password = "i<3bowling"
49
51
  end
@@ -88,3 +90,5 @@ If you want to contribute to the project, see CONTRIBUTING.md for details. It co
88
90
  * Nikita Vasiliev ([@sharpyfox](https://github.com/sharpyfox)): Contributor
89
91
  * Dirk Breuer ([@railsbros-dirk](https://github.com/railsbros-dirk)): Contributor
90
92
  * Mike Williamson ([@sleepycat](https://github.com/sleepycat)): Contributor
93
+ * Ujjwal Thaakar ([@ujjwalt](https://github.com/ujjwalt)): Contributor
94
+ * René Föhring ([@rrrene](https://github.com/rrrene)): Contributor
data/Rakefile CHANGED
@@ -34,6 +34,7 @@ namespace :metrics do
34
34
 
35
35
  desc 'Run mutant to check for mutation coverage'
36
36
  task :mutant do
37
+ raise 'mutant-rspec is not compatible with RSpec 3.0.0 right now'
37
38
  require 'mutant'
38
39
  require 'mutant-rspec'
39
40
 
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.license = 'Apache License 2.0'
14
14
 
15
15
  gem.required_ruby_version = '>= 1.9.3'
16
- gem.requirements << 'ArangoDB, v2.0'
16
+ gem.requirements << 'ArangoDB, v2.1'
17
17
 
18
18
  gem.rubyforge_project = 'ashikawa-core'
19
19
 
@@ -25,23 +25,23 @@ Gem::Specification.new do |gem|
25
25
  # Runtime Dependencies
26
26
  gem.add_dependency 'faraday', '~> 0.9.0'
27
27
  gem.add_dependency 'faraday_middleware', '~> 0.9.1'
28
- gem.add_dependency 'json', '~> 1.8.1'
29
- gem.add_dependency 'null_logger', '~> 0.0.1'
30
28
  gem.add_dependency 'equalizer', '~> 0.0.8'
31
29
 
32
30
  # Development Dependencies
33
- gem.add_development_dependency 'rake', '~> 10.3.1'
34
- gem.add_development_dependency 'rspec', '~> 3.0.0.beta2'
31
+ gem.add_development_dependency 'rake', '~> 10.3.2'
32
+ gem.add_development_dependency 'json', '~> 1.8.1'
33
+ gem.add_development_dependency 'rspec', '~> 3.0.0'
35
34
  gem.add_development_dependency 'rspec-its', '~> 1.0.1'
36
35
  gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.3.0'
36
+ gem.add_development_dependency 'logging', '~> 1.8.1'
37
37
  gem.add_development_dependency 'yard', '~> 0.8.7.4'
38
- gem.add_development_dependency 'inch', '~> 0.4.5'
38
+ gem.add_development_dependency 'inch', '~> 0.4.6'
39
39
  gem.add_development_dependency 'reek', '~> 1.3.7'
40
- gem.add_development_dependency 'mutant', '~> 0.5.12'
41
- gem.add_development_dependency 'mutant-rspec', '~> 0.5.3'
40
+ # gem.add_development_dependency 'mutant', '~> 0.5.18'
41
+ # gem.add_development_dependency 'mutant-rspec', '~> 0.5.17'
42
42
  gem.add_development_dependency 'pry', '~> 0.9.12.6'
43
43
  gem.add_development_dependency 'guard', '~> 2.6.1'
44
- # gem.add_development_dependency 'guard-rspec', '~> 4.2.8'
44
+ gem.add_development_dependency 'guard-rspec', '~> 4.2.9'
45
45
  gem.add_development_dependency 'guard-bundler', '~> 2.0.0'
46
46
 
47
47
  # Rubinius specific dependencies
@@ -49,6 +49,4 @@ Gem::Specification.new do |gem|
49
49
  gem.add_dependency 'rubysl-base64'
50
50
  gem.add_dependency 'rubysl-singleton'
51
51
  end
52
-
53
- # JRuby specific dependencies
54
52
  end
@@ -30,7 +30,7 @@ IrresponsibleModule:
30
30
  LongParameterList:
31
31
  enabled: true
32
32
  exclude: []
33
- max_params: 3
33
+ max_params: 4
34
34
  overrides: {}
35
35
  LongYieldList:
36
36
  enabled: true
@@ -45,7 +45,6 @@ NilCheck:
45
45
  enabled: true
46
46
  exclude:
47
47
  - Ashikawa::Core::Configuration#setup_new_connection
48
- - Ashikawa::Core::Connection#database_name
49
48
  RepeatedConditional:
50
49
  enabled: true
51
50
  exclude:
@@ -54,7 +53,7 @@ RepeatedConditional:
54
53
  TooManyInstanceVariables:
55
54
  enabled: true
56
55
  exclude: []
57
- max_instance_variables: 12
56
+ max_instance_variables: 6
58
57
  TooManyMethods:
59
58
  enabled: true
60
59
  exclude:
@@ -64,7 +63,8 @@ TooManyMethods:
64
63
  TooManyStatements:
65
64
  enabled: true
66
65
  exclude:
67
- - Ashikawa::Core::Connection#initialize
66
+ - Ashikawa::Core::FaradayFactory#self.create_connection
67
+ - Ashikawa::Core::FaradayFactory#faraday_for
68
68
  - Ashikawa::Core::ErrorResponse#on_complete
69
69
  - Ashikawa::Core::Figure#initialize
70
70
  max_statements: 6
@@ -107,5 +107,5 @@ UtilityFunction:
107
107
  exclude: []
108
108
  max_helper_calls: 0
109
109
  PrimaDonnaMethod:
110
- enabled: false
110
+ enabled: true
111
111
  exclude: []
@@ -420,7 +420,11 @@ module Ashikawa
420
420
  # @example Add a hash-index to the fields :name and :profession of a collection
421
421
  # people = database['people']
422
422
  # people.add_index(:hash, :on => [:name, :profession])
423
+ # @example Add a hash-index to the field :email of a collection
424
+ # user = database['user']
425
+ # user.add_index(:hash, :on => :email)
423
426
  def add_index(type, options)
427
+ options[:on] = [options[:on]].flatten
424
428
  unique = options.fetch(:unique, false)
425
429
  response = send_request("index?collection=#{@id}", post: {
426
430
  'type' => type.to_s,
@@ -35,6 +35,11 @@ module Ashikawa
35
35
  # @return String
36
36
  attr_accessor :password
37
37
 
38
+ # The name of the database you want to talk with
39
+ # @api private
40
+ # @return String
41
+ attr_writer :database_name
42
+
38
43
  # The Connection object
39
44
  # @api private
40
45
  # @return Connection
@@ -44,6 +49,13 @@ module Ashikawa
44
49
  @connection
45
50
  end
46
51
 
52
+ # The name of the database you want to talk with
53
+ # @api private
54
+ # @return String
55
+ def database_name
56
+ @database_name ||= '_system'
57
+ end
58
+
47
59
  private
48
60
 
49
61
  # Setup the connection object
@@ -56,7 +68,7 @@ module Ashikawa
56
68
  def setup_new_connection
57
69
  raise(ArgumentError, 'Please provide either an url or a connection to setup the database') if url.nil?
58
70
 
59
- Connection.new(url, connection_options)
71
+ Connection.new(url, database_name, connection_options)
60
72
  end
61
73
 
62
74
  def connection_options
@@ -1,11 +1,9 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'forwardable'
3
3
  require 'faraday'
4
- require 'null_logger'
5
- require 'uri'
6
4
  require 'equalizer'
7
- require 'faraday_middleware'
8
5
  require 'ashikawa-core/error_response'
6
+ require 'ashikawa-core/faraday_factory'
9
7
 
10
8
  module Ashikawa
11
9
  module Core
@@ -21,7 +19,7 @@ module Ashikawa
21
19
  # @return [String]
22
20
  # @api public
23
21
  # @example Get the host part of the connection
24
- # connection = Connection.new('http://localhost:8529')
22
+ # connection = Connection.new('http://localhost:8529', '_system')
25
23
  # connection.host # => 'localhost'
26
24
  def_delegator :@connection, :host
27
25
 
@@ -31,7 +29,7 @@ module Ashikawa
31
29
  # @return [String]
32
30
  # @api public
33
31
  # @example Get the scheme of the connection
34
- # connection = Connection.new('http://localhost:8529')
32
+ # connection = Connection.new('http://localhost:8529', '_system')
35
33
  # connection.scheme # => 'http'
36
34
  def_delegator :@connection, :scheme
37
35
 
@@ -41,7 +39,7 @@ module Ashikawa
41
39
  # @return [Fixnum]
42
40
  # @api public
43
41
  # @example Get the port of the connection
44
- # connection = Connection.new('http://localhost:8529')
42
+ # connection = Connection.new('http://localhost:8529', '_system')
45
43
  # connection.port # => 8529
46
44
  def_delegator :@connection, :port
47
45
 
@@ -50,47 +48,42 @@ module Ashikawa
50
48
  # @return [Faraday]
51
49
  # @api public
52
50
  # @example Set additional response middleware
53
- # connection = Connection.new('http://localhost:8529')
51
+ # connection = Connection.new('http://localhost:8529', '_system')
54
52
  # connection.connection.response :caching
55
53
  attr_reader :connection
56
54
 
55
+ # The name of the database you want to talk with
56
+ # @return [String]
57
+ # @api public
58
+ # @example Get the name of the database
59
+ # connection = Connection.new('http://localhost:8529', 'ashikawa')
60
+ # connection.database_name # => 'ashikawa'
61
+ attr_reader :database_name
62
+
57
63
  # Initialize a Connection with a given API String
58
64
  #
59
65
  # @param [String] api_string scheme, hostname and port as a String
66
+ # @param [String] database_name The name of the database you want to communicate with
60
67
  # @option options [Object] adapter The Faraday adapter you want to use. Defaults to Default Adapter
61
- # @option options [Object] logger The logger you want to use. Defaults to Null Logger.
62
- # @api public
63
- # @example Create a new Connection
64
- # connection = Connection.new('http://localhost:8529')
65
- def initialize(api_string, options = {})
66
- logger = options.fetch(:logger) { NullLogger.instance }
67
- adapter = options.fetch(:adapter) { Faraday.default_adapter }
68
-
69
- @connection = Faraday.new("#{api_string}/_api") do |connection|
70
- connection.request :json
71
-
72
- connection.response :logger, logger
73
- connection.response :error_response
74
- connection.response :json
75
-
76
- connection.adapter(*adapter)
77
- end
78
- end
79
-
80
- # Get the name of the current database
81
- #
68
+ # @option options [Object] debug_headers Should HTTP header be logged or not
69
+ # @option options [Object] logger The logger you want to use. Defaults to no logger.
70
+ # @option options [Array] additional_request_middlewares Additional request middlewares
71
+ # @option options [Array] additional_response_middlewares Additional response middlewares
72
+ # @option options [Array] additional_middlewares Additional middlewares
82
73
  # @api public
83
- # @example Get the name of the database
84
- # connection = Connection.new('http://localhost:8529/_db/ashikawa')
85
- # connection.database_name # => 'ashikawa'
86
- def database_name
87
- database_regexp = %r{_db/(?<db_name>\w+)/_api}
88
- result = @connection.url_prefix.to_s.match(database_regexp)
89
- if result.nil?
90
- '_system'
91
- else
92
- result['db_name']
93
- end
74
+ # @example Create a new Connection with no additional options
75
+ # connection = Connection.new('http://localhost:8529', '_system')
76
+ # @example Create a new Connection with additional options
77
+ # connection = Connection.new('http://localhost:8529', '_system', {
78
+ # adapter: :typhoeus,
79
+ # logger: Yell.new(STDOUT),
80
+ # additional_request_middleware: [:my_request_middleware]
81
+ # additional_response_middleware: [:my_response_middleware]
82
+ # })
83
+ def initialize(api_string, database_name, options = {})
84
+ @api_string = api_string
85
+ @database_name = database_name
86
+ @connection = FaradayFactory.create_connection("#{api_string}/_db/#{database_name}/_api", options)
94
87
  end
95
88
 
96
89
  # Sends a request to a given path returning the parsed result
@@ -124,7 +117,7 @@ module Ashikawa
124
117
  # @example post request
125
118
  # connection.send_request('/collection/new_collection', :post => { :name => 'new_collection' })
126
119
  def send_request_without_database_suffix(path, params = {})
127
- send_request(uri_without_database_suffix(path), params)
120
+ send_request("#{@api_string}/_api/#{path}", params)
128
121
  end
129
122
 
130
123
  # Checks if authentication for this Connection is active or not
@@ -132,7 +125,7 @@ module Ashikawa
132
125
  # @return [Boolean]
133
126
  # @api public
134
127
  # @example Is authentication activated for this connection?
135
- # connection = Connection.new('http://localhost:8529')
128
+ # connection = Connection.new('http://localhost:8529', '_system')
136
129
  # connection.authentication? #=> false
137
130
  # connection.authenticate_with(:username => 'james', :password => 'bond')
138
131
  # connection.authentication? #=> true
@@ -152,17 +145,6 @@ module Ashikawa
152
145
 
153
146
  private
154
147
 
155
- # Build an URI without the database suffix
156
- #
157
- # @param [String] additional_path The path you want to access
158
- # @return [URI] The resulting URI
159
- # @api private
160
- def uri_without_database_suffix(additional_path = '')
161
- uri = @connection.url_prefix
162
- base_uri = [uri.scheme, '://', uri.host, ':', uri.port].join
163
- [base_uri, '_api', additional_path].join('/')
164
- end
165
-
166
148
  # Return the HTTP Verb for the given parameters
167
149
  #
168
150
  # @param [Hash] params The params given to the method
@@ -36,7 +36,7 @@ module Ashikawa
36
36
  # config.url = 'http://localhost:8529'
37
37
  # end
38
38
  # @example Access a Database by providing a Connection and authentication
39
- # connection = Connection.new('http://localhost:8529')
39
+ # connection = Connection.new('http://localhost:8529', '_system')
40
40
  # database = Ashikawa::Core::Database.new do |config|
41
41
  # config.connection = connection
42
42
  # config.username = 'lebowski'
@@ -44,8 +44,9 @@ module Ashikawa
44
44
  # end
45
45
  # @example Access a certain database from ArangoDB
46
46
  # database = Ashikawa::Core::Database.new do |config|
47
- # config.url = 'http://localhost:8529/_db/my_db'
47
+ # config.url = 'http://localhost:8529'
48
48
  # config.connection = connection
49
+ # config.database_name = 'my_db'
49
50
  # end
50
51
  # @example Access a Database with a logger and custom HTTP adapter
51
52
  # database = Ashikawa::Core::Database.new do |config|
@@ -63,7 +64,8 @@ module Ashikawa
63
64
  #
64
65
  # @example Create a new database with the name 'ashikawa'
65
66
  # database = Ashikawa::Core::Database.new do |config|
66
- # config.url = 'http://localhost:8529/_db/ashikawa'
67
+ # config.url = 'http://localhost:8529'
68
+ # config.database_name = 'ashikawa'
67
69
  # end
68
70
  # database.create
69
71
  def create
@@ -74,7 +76,8 @@ module Ashikawa
74
76
  #
75
77
  # @example Drop a new database with the name 'ashikawa'
76
78
  # database = Ashikawa::Core::Database.new do |config|
77
- # config.url = 'http://localhost:8529/_db/ashikawa'
79
+ # config.url = 'http://localhost:8529'
80
+ # config.database_name = 'ashikawa'
78
81
  # end
79
82
  # database.drop
80
83
  def drop
@@ -98,7 +101,8 @@ module Ashikawa
98
101
  # @api public
99
102
  # @example Get the name of the databasse
100
103
  # database = Ashikawa::Core::Database.new do |config|
101
- # config.url = 'http://localhost:8529/_api/ashikawa'
104
+ # config.url = 'http://localhost:8529'
105
+ # config.database_name = 'ashikawa'
102
106
  # end
103
107
  # database.name # => 'ashikawa'
104
108
  def name
@@ -56,8 +56,8 @@ module Ashikawa
56
56
  # @api semipublic
57
57
  # @example Check if the document is persisted
58
58
  # document = Ashikawa::Core::Document.new(database, raw_document)
59
- # document.check_if_persisted!
60
- def check_if_persisted!
59
+ # document.check_if_persisted
60
+ def check_if_persisted
61
61
  raise DocumentNotFoundException if @id == :not_persisted
62
62
  end
63
63
 
@@ -81,7 +81,7 @@ module Ashikawa
81
81
  # document = Ashikawa::Core::Document.new(database, raw_document)
82
82
  # document.delete
83
83
  def delete
84
- check_if_persisted!
84
+ check_if_persisted
85
85
  send_request_for_document(delete: {})
86
86
  end
87
87
 
@@ -118,7 +118,7 @@ module Ashikawa
118
118
  # document['occupation'] = 'Not occupied'
119
119
  # document.save
120
120
  def save
121
- check_if_persisted!
121
+ check_if_persisted
122
122
  send_request_for_document(put: @content)
123
123
  end
124
124
 
@@ -128,8 +128,8 @@ module Ashikawa
128
128
  # @api public
129
129
  # @example Refresh the document
130
130
  # document = Ashikawa::Core::Document.new(database, raw_document)
131
- # document.refresh!
132
- def refresh!
131
+ # document.refresh
132
+ def refresh
133
133
  parse_raw_document(send_request_for_document)
134
134
  end
135
135