ashikawa-core 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/{config/rubocop.yml → .hound.yml} +17 -2
- data/.ruby-version +1 -1
- data/.travis.yml +6 -6
- data/CHANGELOG.md +22 -0
- data/Gemfile +3 -4
- data/Guardfile +3 -3
- data/README.md +12 -11
- data/Rakefile +52 -6
- data/ashikawa-core.gemspec +42 -19
- data/config/mutant.yml +1 -3
- data/config/reek.yml +3 -1
- data/lib/ashikawa-core/collection.rb +9 -7
- data/lib/ashikawa-core/configuration.rb +1 -1
- data/lib/ashikawa-core/connection.rb +43 -0
- data/lib/ashikawa-core/database.rb +61 -2
- data/lib/ashikawa-core/error_response.rb +14 -3
- data/lib/ashikawa-core/exceptions/client_error.rb +4 -4
- data/lib/ashikawa-core/exceptions/client_error/bad_syntax.rb +3 -2
- data/lib/ashikawa-core/exceptions/server_error.rb +4 -4
- data/lib/ashikawa-core/key_options.rb +3 -2
- data/lib/ashikawa-core/query.rb +33 -29
- data/lib/ashikawa-core/status.rb +9 -0
- data/lib/ashikawa-core/transaction.rb +3 -3
- data/lib/ashikawa-core/version.rb +1 -1
- data/spec/acceptance/basic_spec.rb +14 -8
- data/spec/acceptance/index_spec.rb +2 -2
- data/spec/acceptance/query_spec.rb +4 -4
- data/spec/acceptance/spec_helper.rb +24 -9
- data/spec/acceptance/transactions_spec.rb +2 -2
- data/spec/unit/collection_spec.rb +3 -3
- data/spec/unit/connection_spec.rb +38 -6
- data/spec/unit/database_spec.rb +58 -7
- data/spec/unit/document_spec.rb +3 -3
- data/spec/unit/exception_spec.rb +5 -1
- data/spec/unit/index_spec.rb +6 -1
- data/spec/unit/query_spec.rb +32 -22
- data/spec/unit/spec_helper.rb +5 -20
- data/spec/unit/status_spec.rb +25 -25
- data/spec/unit/transaction_spec.rb +4 -4
- metadata +192 -31
- data/.coveralls.yml +0 -1
- data/Gemfile.devtools +0 -71
- data/config/devtools.yml +0 -5
- data/config/flay.yml +0 -3
- data/config/flog.yml +0 -3
- data/config/yardstick.yml +0 -2
- data/tasks/adjustments.rake +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 243fdb95bc1ad7691bc5129b1dce1f85ad929792
|
4
|
+
data.tar.gz: e5bc4fda8b7d97e6bf90cf8570227afaff1b9128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31d2dcb8dc2b0ad4c431181cac8cc22daf224215791406dca9d81e4f78f472187e156a4b9e7f36a38a1bc4f9d9f5dfc7bfc806a2c24def3265eefb1d455e6362
|
7
|
+
data.tar.gz: d0bc42d3059d787ea3747c279c0c522d4bcb4558cae5978529e33945726ba3f8f7260c90a447f6a97700f7d19b449d9bd1da03a805426b87ac0223c90cd2ce0d
|
data/.gitignore
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
AllCops:
|
2
|
-
|
2
|
+
Include:
|
3
3
|
- '../**/*.rake'
|
4
4
|
- 'Gemfile'
|
5
5
|
- 'Guardfile'
|
6
6
|
- 'Rakefile'
|
7
|
-
|
7
|
+
Exclude:
|
8
8
|
- !ruby/regexp /spec\/setup/
|
9
9
|
|
10
10
|
# Avoid parameter lists longer than five parameters.
|
@@ -37,6 +37,9 @@ LineLength:
|
|
37
37
|
Enabled: true
|
38
38
|
Max: 120
|
39
39
|
|
40
|
+
DotPosition:
|
41
|
+
EnforcedStyle: 'leading'
|
42
|
+
|
40
43
|
SpaceInsideHashLiteralBraces:
|
41
44
|
Enabled: true
|
42
45
|
|
@@ -95,3 +98,15 @@ SignalException:
|
|
95
98
|
ClassLength:
|
96
99
|
CountComments: false
|
97
100
|
Max: 140
|
101
|
+
|
102
|
+
# The suggested style does not match the common ruby way of aligning the content of a hash
|
103
|
+
IndentHash:
|
104
|
+
Enabled: false
|
105
|
+
|
106
|
+
# This cop seems to not work correctly. Also we don't agree with it.
|
107
|
+
FileName:
|
108
|
+
Enabled: false
|
109
|
+
|
110
|
+
# Double negations are extremely useful
|
111
|
+
DoubleNegation:
|
112
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.1.
|
1
|
+
ruby-2.1.2
|
data/.travis.yml
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
language: ruby
|
2
|
-
before_install:
|
3
|
-
- gem install bundler -v '= 1.5.1' # http://changelog.travis-ci.com/post/71633370723/mri-ruby-2-1-0-and-jruby-1-7-9-available
|
4
2
|
before_script:
|
5
3
|
- ./spec/setup/arangodb.sh
|
6
4
|
rvm:
|
7
5
|
- 1.9.3
|
8
6
|
- 2.0.0
|
9
|
-
- 2.1.
|
10
|
-
- jruby-
|
11
|
-
- rbx-2.2.
|
7
|
+
- 2.1.2
|
8
|
+
- jruby-1.7.12
|
9
|
+
- rbx-2.2.6
|
12
10
|
env:
|
13
|
-
- ARANGODB_DISABLE_AUTHENTIFICATION=false VERSION=1.4
|
14
11
|
- ARANGODB_DISABLE_AUTHENTIFICATION=false VERSION=2.0
|
15
12
|
matrix:
|
16
13
|
allow_failures:
|
17
14
|
- rvm: 2.1.0
|
18
15
|
script: "bundle exec rake ci"
|
16
|
+
addons:
|
17
|
+
code_climate:
|
18
|
+
repo_token: 4d49e70568a106875f85f2918698df75118b4a83af20ad57317b10f5fc40d5e0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
# Version 0.11
|
2
|
+
|
3
|
+
**Codename: R3C0NF1GUR3D**
|
4
|
+
|
5
|
+
* Only supports ArangoDB 2.0 officially from now on.
|
6
|
+
* **Breaking Change:** Collection#truncate! is now Collection#truncate
|
7
|
+
* New feature: Create and Drop Databases – and get their name and truncate all collections at once #103
|
8
|
+
* New feature: Allow to pass `bind_vars` to the execution of AQL #107 #113
|
9
|
+
* Dependency Update: Faraday and Faraday Middleware #111
|
10
|
+
* Documentation Improvements #95
|
11
|
+
* README improvements #100 #102 #106
|
12
|
+
* Development Setup Changes:
|
13
|
+
* Removed Devtools entirely #93
|
14
|
+
* Updated to RSpec 3.0 #94 #112
|
15
|
+
* Use HoundCI as our code style checker #105
|
16
|
+
* Use Inch for documentation checking #93
|
17
|
+
* Bring all development dependencies up to date #111
|
18
|
+
* New Contributors
|
19
|
+
* Mike Williamson (@sleepycat)
|
20
|
+
|
21
|
+
*Codename in honor of Daft Punk.*
|
22
|
+
|
1
23
|
# Version 0.10
|
2
24
|
|
3
25
|
**Codename: Sepia Tone Laboratory**
|
data/Gemfile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
source 'https://rubygems.org'
|
3
3
|
|
4
|
-
# Specify your gem's dependencies in ashikawa-core.gemspec
|
5
4
|
gemspec
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
%w( core mocks expectations support its ).each do |name|
|
7
|
+
gem "rspec-#{name}", github: "rspec/rspec-#{name}"
|
8
|
+
end
|
data/Guardfile
CHANGED
@@ -3,7 +3,7 @@ guard 'bundler' do
|
|
3
3
|
watch(/^.+\.gemspec/)
|
4
4
|
end
|
5
5
|
|
6
|
-
guard 'rspec',
|
7
|
-
watch(
|
8
|
-
watch(%r{lib/ashikawa-core/(.+)\.rb$})
|
6
|
+
guard 'rspec', cmd: 'bundle exec rspec' do
|
7
|
+
watch(/^spec\/.+_spec\.rb/)
|
8
|
+
watch(%r{^lib/ashikawa-core/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
|
9
9
|
end
|
data/README.md
CHANGED
@@ -4,20 +4,18 @@
|
|
4
4
|
|:----------------|:--------------------------------------------------
|
5
5
|
| Homepage | http://triagens.github.io/ashikawa-core/
|
6
6
|
| Documentation | [RubyDoc](http://www.rubydoc.info/gems/ashikawa-core)
|
7
|
-
| CI | [![Build Status](
|
8
|
-
| Code Metrics | [![Code Climate](https://codeclimate.com/github/triAGENS/ashikawa-core.
|
9
|
-
| Gem Version | [![Gem Version](
|
10
|
-
| Dependencies | [![Dependency Status](
|
7
|
+
| CI | [![Build Status](http://img.shields.io/travis/triAGENS/ashikawa-core.svg)](http://travis-ci.org/triAGENS/ashikawa-core)
|
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
|
+
| Gem Version | [![Gem Version](http://img.shields.io/gem/v/ashikawa-core.svg)](http://rubygems.org/gems/ashikawa-core)
|
10
|
+
| Dependencies | [![Dependency Status](http://img.shields.io/gemnasium/triAGENS/ashikawa-core.svg)](https://gemnasium.com/triAGENS/ashikawa-core)
|
11
11
|
|
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 **
|
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
13
|
|
14
14
|
All tests run on Travis CI for the following versions of Ruby:
|
15
15
|
|
16
|
-
* MRI 1.9.3, 2.0.0 and 2.1.
|
17
|
-
* Rubinius 2.2.
|
18
|
-
* JRuby 1.7.
|
19
|
-
|
20
|
-
Please note that the [`master`](https://github.com/triAGENS/ashikawa-core) branch is always the stable version released on Ruby Gems and documented on [RDoc](http://www.rubydoc.info/github/triAGENS/ashikawa-core). If you want the most recent version, please refer to the [`development`](https://github.com/triAGENS/ashikawa-core/tree/development) branch.
|
16
|
+
* MRI 1.9.3, 2.0.0 and 2.1.2
|
17
|
+
* Rubinius 2.2.6
|
18
|
+
* JRuby 1.7.12
|
21
19
|
|
22
20
|
## How to install it?
|
23
21
|
|
@@ -28,7 +26,7 @@ gem install ashikawa-core
|
|
28
26
|
or, when using bundler:
|
29
27
|
|
30
28
|
```ruby
|
31
|
-
gem "ashikawa-core", "~> 0.
|
29
|
+
gem "ashikawa-core", "~> 0.11"
|
32
30
|
```
|
33
31
|
|
34
32
|
## How to Setup a Connection?
|
@@ -87,3 +85,6 @@ If you want to contribute to the project, see CONTRIBUTING.md for details. It co
|
|
87
85
|
* Markus Schirp ([@mbj](https://github.com/mbj)): Contributor
|
88
86
|
* Ettore Berardi ([@ettomatic](https://github.com/ettomatic)): Contributor
|
89
87
|
* Samuel Richardson ([@Rodeoclash](https://github.com/Rodeoclash)): Contributor
|
88
|
+
* Nikita Vasiliev ([@sharpyfox](https://github.com/sharpyfox)): Contributor
|
89
|
+
* Dirk Breuer ([@railsbros-dirk](https://github.com/railsbros-dirk)): Contributor
|
90
|
+
* Mike Williamson ([@sleepycat](https://github.com/sleepycat)): Contributor
|
data/Rakefile
CHANGED
@@ -1,12 +1,58 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
1
|
# -*- encoding : utf-8 -*-
|
3
|
-
require 'devtools'
|
4
2
|
require 'bundler/gem_tasks'
|
5
3
|
require 'rspec/core/rake_task'
|
4
|
+
require 'yard/rake/yardoc_task'
|
5
|
+
require 'inch/rake'
|
6
|
+
require 'reek/rake/task'
|
6
7
|
|
7
|
-
|
8
|
+
desc 'Run all specs'
|
9
|
+
task spec: ['spec:unit', 'spec:acceptance']
|
8
10
|
|
9
|
-
|
11
|
+
namespace :spec do
|
12
|
+
desc 'Run unit specs'
|
13
|
+
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
+
task.pattern = 'spec/unit/**/*_spec.rb'
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
|
17
|
+
desc 'Run acceptance specs – requires running instance of ArangoDB'
|
18
|
+
RSpec::Core::RakeTask.new(:acceptance) do |task|
|
19
|
+
task.pattern = 'spec/acceptance/**/*_spec.rb'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
YARD::Rake::YardocTask.new(:doc)
|
24
|
+
|
25
|
+
namespace :metrics do
|
26
|
+
Inch::Rake::Suggest.new do |t|
|
27
|
+
t.args << '--pedantic'
|
28
|
+
end
|
29
|
+
|
30
|
+
Reek::Rake::Task.new do |t|
|
31
|
+
t.fail_on_error = true
|
32
|
+
t.config_files = 'config/reek.yml'
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Run mutant to check for mutation coverage'
|
36
|
+
task :mutant do
|
37
|
+
require 'mutant'
|
38
|
+
require 'mutant-rspec'
|
39
|
+
|
40
|
+
namespaces = YAML.load_file('config/mutant.yml').map { |n| "::#{n}*" }
|
41
|
+
arguments = %w(--include lib --require ashikawa-core --use rspec).concat(namespaces)
|
42
|
+
status = Mutant::CLI.run(arguments)
|
43
|
+
exit 'Mutant task is not successful' if status.nonzero?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'Start a REPL with guacamole loaded (not the Rails part)'
|
48
|
+
task :console do
|
49
|
+
require 'bundler/setup'
|
50
|
+
|
51
|
+
require 'pry'
|
52
|
+
require 'ashikawa-core'
|
53
|
+
ARGV.clear
|
54
|
+
Pry.start
|
55
|
+
end
|
56
|
+
|
57
|
+
task default: :spec
|
58
|
+
task ci: ['spec', 'metrics:reek']
|
data/ashikawa-core.gemspec
CHANGED
@@ -1,31 +1,54 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
3
|
-
require
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'ashikawa-core/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
|
-
gem.name =
|
6
|
+
gem.name = 'ashikawa-core'
|
7
7
|
gem.version = Ashikawa::Core::VERSION
|
8
|
-
gem.authors = [
|
9
|
-
gem.email = [
|
10
|
-
gem.homepage =
|
11
|
-
gem.summary =
|
12
|
-
gem.description =
|
13
|
-
gem.license =
|
8
|
+
gem.authors = ['moonglum']
|
9
|
+
gem.email = ['me@moonglum.net']
|
10
|
+
gem.homepage = 'http://triagens.github.com/ashikawa-core'
|
11
|
+
gem.summary = 'Ashikawa Core is a wrapper around the ArangoDB REST API'
|
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.'
|
13
|
+
gem.license = 'Apache License 2.0'
|
14
14
|
|
15
15
|
gem.required_ruby_version = '>= 1.9.3'
|
16
|
-
gem.requirements <<
|
16
|
+
gem.requirements << 'ArangoDB, v2.0'
|
17
17
|
|
18
|
-
gem.rubyforge_project =
|
18
|
+
gem.rubyforge_project = 'ashikawa-core'
|
19
19
|
|
20
20
|
gem.files = `git ls-files`.split("\n")
|
21
21
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
22
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
-
gem.require_paths = [
|
24
|
-
|
25
|
-
|
26
|
-
gem.add_dependency
|
27
|
-
gem.add_dependency
|
28
|
-
gem.add_dependency
|
29
|
-
gem.add_dependency
|
30
|
-
gem.add_dependency
|
23
|
+
gem.require_paths = ['lib']
|
24
|
+
|
25
|
+
# Runtime Dependencies
|
26
|
+
gem.add_dependency 'faraday', '~> 0.9.0'
|
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
|
+
gem.add_dependency 'equalizer', '~> 0.0.8'
|
31
|
+
|
32
|
+
# Development Dependencies
|
33
|
+
gem.add_development_dependency 'rake', '~> 10.3.1'
|
34
|
+
gem.add_development_dependency 'rspec', '~> 3.0.0.beta2'
|
35
|
+
gem.add_development_dependency 'rspec-its', '~> 1.0.1'
|
36
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.3.0'
|
37
|
+
gem.add_development_dependency 'yard', '~> 0.8.7.4'
|
38
|
+
gem.add_development_dependency 'inch', '~> 0.4.5'
|
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'
|
42
|
+
gem.add_development_dependency 'pry', '~> 0.9.12.6'
|
43
|
+
gem.add_development_dependency 'guard', '~> 2.6.1'
|
44
|
+
# gem.add_development_dependency 'guard-rspec', '~> 4.2.8'
|
45
|
+
gem.add_development_dependency 'guard-bundler', '~> 2.0.0'
|
46
|
+
|
47
|
+
# Rubinius specific dependencies
|
48
|
+
if RUBY_ENGINE == 'rbx'
|
49
|
+
gem.add_dependency 'rubysl-base64'
|
50
|
+
gem.add_dependency 'rubysl-singleton'
|
51
|
+
end
|
52
|
+
|
53
|
+
# JRuby specific dependencies
|
31
54
|
end
|
data/config/mutant.yml
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
---
|
2
|
-
name: ashikawa-core
|
3
|
-
namespace:
|
4
2
|
# - Ashikawa::Core::Collection
|
5
3
|
- Ashikawa::Core::Configuration
|
6
4
|
# - Ashikawa::Core::Connection
|
@@ -9,7 +7,7 @@ namespace:
|
|
9
7
|
- Ashikawa::Core::Document
|
10
8
|
- Ashikawa::Core::Edge
|
11
9
|
- Ashikawa::Core::Figure
|
12
|
-
- Ashikawa::Core::Index
|
10
|
+
# - Ashikawa::Core::Index
|
13
11
|
- Ashikawa::Core::KeyOptions
|
14
12
|
# - Ashikawa::Core::Query
|
15
13
|
- Ashikawa::Core::Status
|
data/config/reek.yml
CHANGED
@@ -45,6 +45,7 @@ NilCheck:
|
|
45
45
|
enabled: true
|
46
46
|
exclude:
|
47
47
|
- Ashikawa::Core::Configuration#setup_new_connection
|
48
|
+
- Ashikawa::Core::Connection#database_name
|
48
49
|
RepeatedConditional:
|
49
50
|
enabled: true
|
50
51
|
exclude:
|
@@ -58,6 +59,7 @@ TooManyMethods:
|
|
58
59
|
enabled: true
|
59
60
|
exclude:
|
60
61
|
- Ashikawa::Core::Collection
|
62
|
+
- Ashikawa::Core::Database
|
61
63
|
max_methods: 15
|
62
64
|
TooManyStatements:
|
63
65
|
enabled: true
|
@@ -65,7 +67,7 @@ TooManyStatements:
|
|
65
67
|
- Ashikawa::Core::Connection#initialize
|
66
68
|
- Ashikawa::Core::ErrorResponse#on_complete
|
67
69
|
- Ashikawa::Core::Figure#initialize
|
68
|
-
max_statements:
|
70
|
+
max_statements: 6
|
69
71
|
UncommunicativeMethodName:
|
70
72
|
enabled: true
|
71
73
|
exclude: []
|
@@ -18,11 +18,13 @@ module Ashikawa
|
|
18
18
|
|
19
19
|
include Equalizer.new(:id, :name, :content_type, :database)
|
20
20
|
|
21
|
+
# ArangoDB's collections contain either only documents or only edges
|
21
22
|
CONTENT_TYPES = {
|
22
23
|
2 => :document,
|
23
24
|
3 => :edge
|
24
25
|
}
|
25
26
|
|
27
|
+
# Map the content types to the classes from Ashikawa
|
26
28
|
CONTENT_CLASS = {
|
27
29
|
document: Document,
|
28
30
|
edge: Edge
|
@@ -337,14 +339,14 @@ module Ashikawa
|
|
337
339
|
# 'code' => 200
|
338
340
|
# }
|
339
341
|
# collection = Ashikawa::Core::Collection.new(database, raw_collection)
|
340
|
-
# collection.truncate
|
341
|
-
def truncate
|
342
|
+
# collection.truncate
|
343
|
+
def truncate
|
342
344
|
send_command_to_server(:truncate)
|
343
345
|
end
|
344
346
|
|
345
347
|
# Fetch a certain document by its key
|
346
348
|
#
|
347
|
-
# @param [
|
349
|
+
# @param [Fixnum] document_key the key of the document
|
348
350
|
# @raise [DocumentNotFoundException] If the requested document was not found
|
349
351
|
# @return Document
|
350
352
|
# @api public
|
@@ -357,7 +359,7 @@ module Ashikawa
|
|
357
359
|
|
358
360
|
# Fetch a certain document by its key, return nil if the document does not exist
|
359
361
|
#
|
360
|
-
# @param [
|
362
|
+
# @param [Fixnum] document_key the id of the document
|
361
363
|
# @return Document
|
362
364
|
# @api public
|
363
365
|
# @example Fetch the document with the key 12345
|
@@ -370,7 +372,7 @@ module Ashikawa
|
|
370
372
|
|
371
373
|
# Replace a document by its key
|
372
374
|
#
|
373
|
-
# @param [
|
375
|
+
# @param [Fixnum] document_key the key of the document
|
374
376
|
# @param [Hash] raw_document the data you want to replace it with
|
375
377
|
# @return [Hash] parsed JSON response from the server
|
376
378
|
# @api public
|
@@ -431,7 +433,7 @@ module Ashikawa
|
|
431
433
|
|
432
434
|
# Get an index by ID
|
433
435
|
#
|
434
|
-
# @param [
|
436
|
+
# @param [Fixnum] id
|
435
437
|
# @return Index
|
436
438
|
# @api public
|
437
439
|
# @example Get an Index by its ID
|
@@ -535,7 +537,7 @@ module Ashikawa
|
|
535
537
|
|
536
538
|
# Send a request for the content with the given key
|
537
539
|
#
|
538
|
-
# @param [
|
540
|
+
# @param [Fixnum] document_key The id of the document
|
539
541
|
# @param [Hash] opts The options for the request
|
540
542
|
# @return [Hash] parsed JSON response from the server
|
541
543
|
# @api private
|
@@ -39,7 +39,7 @@ module Ashikawa
|
|
39
39
|
# @api private
|
40
40
|
# @return Connection
|
41
41
|
def connection
|
42
|
-
@connection
|
42
|
+
@connection ||= setup_new_connection
|
43
43
|
@connection.authenticate_with(username, password) if username && password
|
44
44
|
@connection
|
45
45
|
end
|
@@ -77,6 +77,22 @@ module Ashikawa
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
# Get the name of the current database
|
81
|
+
#
|
82
|
+
# @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
|
94
|
+
end
|
95
|
+
|
80
96
|
# Sends a request to a given path returning the parsed result
|
81
97
|
# @note prepends the api_string automatically
|
82
98
|
#
|
@@ -96,6 +112,21 @@ module Ashikawa
|
|
96
112
|
raise Ashikawa::Core::JsonError
|
97
113
|
end
|
98
114
|
|
115
|
+
# Sends a request to a given path without the database suffix returning the parsed result
|
116
|
+
# @note prepends the api_string automatically
|
117
|
+
#
|
118
|
+
# @param [string] path the path you wish to send a request to.
|
119
|
+
# @option params [hash] :post post data in case you want to send a post request.
|
120
|
+
# @return [hash] parsed json response from the server
|
121
|
+
# @api public
|
122
|
+
# @example get request
|
123
|
+
# connection.send_request('/collection/new_collection')
|
124
|
+
# @example post request
|
125
|
+
# connection.send_request('/collection/new_collection', :post => { :name => 'new_collection' })
|
126
|
+
def send_request_without_database_suffix(path, params = {})
|
127
|
+
send_request(uri_without_database_suffix(path), params)
|
128
|
+
end
|
129
|
+
|
99
130
|
# Checks if authentication for this Connection is active or not
|
100
131
|
#
|
101
132
|
# @return [Boolean]
|
@@ -113,6 +144,7 @@ module Ashikawa
|
|
113
144
|
#
|
114
145
|
# @param [String] username
|
115
146
|
# @param [String] password
|
147
|
+
# @return [String] Basic Auth info (Base 64 of username:password)
|
116
148
|
# @api private
|
117
149
|
def authenticate_with(username, password)
|
118
150
|
@authentication = @connection.basic_auth(username, password)
|
@@ -120,6 +152,17 @@ module Ashikawa
|
|
120
152
|
|
121
153
|
private
|
122
154
|
|
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
|
+
|
123
166
|
# Return the HTTP Verb for the given parameters
|
124
167
|
#
|
125
168
|
# @param [Hash] params The params given to the method
|