fauna 1.3.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG +2 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +65 -102
- data/Rakefile +12 -20
- data/fauna.gemspec +19 -44
- data/lib/fauna.rb +12 -14
- data/lib/fauna/client.rb +225 -27
- data/lib/fauna/client_logger.rb +52 -0
- data/lib/fauna/context.rb +135 -0
- data/lib/fauna/errors.rb +181 -0
- data/lib/fauna/json.rb +60 -0
- data/lib/fauna/objects.rb +96 -0
- data/lib/fauna/query.rb +601 -0
- data/lib/fauna/request_result.rb +58 -0
- data/lib/fauna/util.rb +41 -0
- data/lib/fauna/version.rb +4 -0
- data/spec/client_logger_spec.rb +73 -0
- data/spec/client_spec.rb +202 -0
- data/spec/context_spec.rb +121 -0
- data/spec/errors_spec.rb +144 -0
- data/spec/fauna_helper.rb +87 -0
- data/spec/json_spec.rb +123 -0
- data/spec/query_spec.rb +675 -0
- data/spec/ref_spec.rb +77 -0
- data/spec/setref_spec.rb +23 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/util_spec.rb +19 -0
- metadata +65 -83
- data/Manifest +0 -25
- data/lib/fauna/cache.rb +0 -64
- data/lib/fauna/connection.rb +0 -152
- data/lib/fauna/named_resource.rb +0 -17
- data/lib/fauna/rails.rb +0 -120
- data/lib/fauna/resource.rb +0 -175
- data/lib/fauna/set.rb +0 -240
- data/lib/tasks/fauna.rake +0 -71
- data/test/class_test.rb +0 -65
- data/test/client_test.rb +0 -63
- data/test/connection_test.rb +0 -66
- data/test/database_test.rb +0 -48
- data/test/query_test.rb +0 -48
- data/test/readme_test.rb +0 -30
- data/test/set_test.rb +0 -71
- data/test/test_helper.rb +0 -86
data/spec/ref_spec.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
RSpec.describe Fauna::Ref do
|
2
|
+
it 'converts to string' do
|
3
|
+
expect(Fauna::Ref.new('classes/test').to_s).to eq('classes/test')
|
4
|
+
end
|
5
|
+
|
6
|
+
describe '#initalize' do
|
7
|
+
it 'creates from string' do
|
8
|
+
name = random_string
|
9
|
+
expect(Fauna::Ref.new("classes/#{name}").value).to eq("classes/#{name}")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'creates from arguments' do
|
13
|
+
name = random_string
|
14
|
+
id = random_number
|
15
|
+
|
16
|
+
expect(Fauna::Ref.new('classes', name).value).to eq("classes/#{name}")
|
17
|
+
expect(Fauna::Ref.new('classes', name, id).value).to eq("classes/#{name}/#{id}")
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'creates from other refs' do
|
21
|
+
ref = Fauna::Ref.new('classes')
|
22
|
+
name = random_string
|
23
|
+
id = random_number
|
24
|
+
|
25
|
+
class_ref = Fauna::Ref.new(ref, name)
|
26
|
+
|
27
|
+
expect(class_ref.value).to eq("classes/#{name}")
|
28
|
+
expect(Fauna::Ref.new(class_ref, id).value).to eq("classes/#{name}/#{id}")
|
29
|
+
expect(Fauna::Ref.new(ref, name, id).value).to eq("classes/#{name}/#{id}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#id' do
|
34
|
+
context 'with multiple elements' do
|
35
|
+
it 'returns id portion' do
|
36
|
+
expect(Fauna::Ref.new('classes', 'test').id).to eq('test')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with single element' do
|
41
|
+
it 'raises error' do
|
42
|
+
expect { Fauna::Ref.new('classes').id }.to raise_error(ArgumentError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#to_class' do
|
48
|
+
context 'with multiple elements' do
|
49
|
+
it 'returns class portion' do
|
50
|
+
expect(Fauna::Ref.new('classes', 'test').to_class).to eq(Fauna::Ref.new('classes'))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with single element' do
|
55
|
+
it 'returns class portion' do
|
56
|
+
expect(Fauna::Ref.new('classes').to_class).to eq(Fauna::Ref.new('classes'))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#==' do
|
62
|
+
it 'equals same ref' do
|
63
|
+
ref = Fauna::Ref.new('classes/test')
|
64
|
+
|
65
|
+
expect(ref).to eq(Fauna::Ref.new('classes/test'))
|
66
|
+
expect(ref.to_class).to eq(Fauna::Ref.new('classes'))
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'does not equal different ref' do
|
70
|
+
expect(Fauna::Ref.new('classes/test')).not_to eq(Fauna::Ref.new('classes'))
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not equal other type' do
|
74
|
+
expect(Fauna::Ref.new('classes/test')).not_to eq('classes/test')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/setref_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
RSpec.describe Fauna::SetRef do
|
2
|
+
describe '#==' do
|
3
|
+
it 'equals same set' do
|
4
|
+
data = { match: random_ref, terms: random_string }
|
5
|
+
set = Fauna::SetRef.new(data)
|
6
|
+
|
7
|
+
expect(set).to eq(Fauna::SetRef.new(data))
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'does not equal different set' do
|
11
|
+
set = Fauna::SetRef.new(match: random_ref, terms: random_string)
|
12
|
+
|
13
|
+
expect(set).not_to eq(Fauna::SetRef.new(match: random_ref, terms: random_string))
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'does not equal other type' do
|
17
|
+
data = { match: random_ref, terms: random_string }
|
18
|
+
set = Fauna::SetRef.new(data)
|
19
|
+
|
20
|
+
expect(set).not_to eq(data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'fauna'
|
3
|
+
require 'fauna_helper'
|
4
|
+
|
5
|
+
# Reference http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.expect_with :rspec do |expectations|
|
8
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
9
|
+
end
|
10
|
+
|
11
|
+
config.mock_with :rspec do |mocks|
|
12
|
+
mocks.verify_partial_doubles = true
|
13
|
+
end
|
14
|
+
|
15
|
+
# Disable monkey patching
|
16
|
+
config.disable_monkey_patching!
|
17
|
+
|
18
|
+
# Enable warnings
|
19
|
+
config.warnings = true
|
20
|
+
|
21
|
+
# Setup test order
|
22
|
+
config.order = :random
|
23
|
+
Kernel.srand config.seed
|
24
|
+
|
25
|
+
# Include test helpers
|
26
|
+
config.include FaunaTestHelpers
|
27
|
+
end
|
data/spec/util_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
RSpec.describe 'Fauna Util' do
|
2
|
+
describe '#time_from_usecs' do
|
3
|
+
it 'converts microseconds to time' do
|
4
|
+
time = Time.at(1, 234_567)
|
5
|
+
usecs = 1_234_567
|
6
|
+
|
7
|
+
expect(Fauna.time_from_usecs(usecs)).to eq(time)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#usecs_from_time' do
|
12
|
+
it 'converts time to microseconds' do
|
13
|
+
time = Time.at(1, 234_567)
|
14
|
+
usecs = 1_234_567
|
15
|
+
|
16
|
+
expect(Fauna.usecs_from_time(time)).to eq(usecs)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,178 +1,160 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fauna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fauna, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.9.0
|
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
26
|
version: 0.9.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.8
|
33
|
+
version: '1.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.8
|
40
|
+
version: '1.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ! '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: minitest
|
56
|
+
name: rubocop
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - ~>
|
59
|
+
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
61
|
+
version: 0.35.0
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - ~>
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
68
|
+
version: 0.35.0
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: coveralls
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- -
|
73
|
+
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
75
|
+
version: 0.8.10
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- -
|
80
|
+
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: 0.8.10
|
97
83
|
description: Ruby client for the Fauna distributed database.
|
98
|
-
email:
|
84
|
+
email: priority@faunadb.com
|
99
85
|
executables: []
|
100
86
|
extensions: []
|
101
87
|
extra_rdoc_files:
|
102
88
|
- CHANGELOG
|
103
89
|
- LICENSE
|
104
90
|
- README.md
|
105
|
-
- lib/fauna.rb
|
106
|
-
- lib/fauna/cache.rb
|
107
|
-
- lib/fauna/client.rb
|
108
|
-
- lib/fauna/connection.rb
|
109
|
-
- lib/fauna/named_resource.rb
|
110
|
-
- lib/fauna/rails.rb
|
111
|
-
- lib/fauna/resource.rb
|
112
|
-
- lib/fauna/set.rb
|
113
|
-
- lib/fauna/util.rb
|
114
|
-
- lib/tasks/fauna.rake
|
115
91
|
files:
|
116
92
|
- CHANGELOG
|
117
93
|
- Gemfile
|
118
94
|
- LICENSE
|
119
|
-
- Manifest
|
120
95
|
- README.md
|
121
96
|
- Rakefile
|
122
97
|
- fauna.gemspec
|
123
98
|
- lib/fauna.rb
|
124
|
-
- lib/fauna/cache.rb
|
125
99
|
- lib/fauna/client.rb
|
126
|
-
- lib/fauna/
|
127
|
-
- lib/fauna/
|
128
|
-
- lib/fauna/
|
129
|
-
- lib/fauna/
|
130
|
-
- lib/fauna/
|
100
|
+
- lib/fauna/client_logger.rb
|
101
|
+
- lib/fauna/context.rb
|
102
|
+
- lib/fauna/errors.rb
|
103
|
+
- lib/fauna/json.rb
|
104
|
+
- lib/fauna/objects.rb
|
105
|
+
- lib/fauna/query.rb
|
106
|
+
- lib/fauna/request_result.rb
|
131
107
|
- lib/fauna/util.rb
|
132
|
-
- lib/
|
133
|
-
-
|
134
|
-
-
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
138
|
-
-
|
139
|
-
-
|
140
|
-
-
|
141
|
-
|
108
|
+
- lib/fauna/version.rb
|
109
|
+
- spec/client_logger_spec.rb
|
110
|
+
- spec/client_spec.rb
|
111
|
+
- spec/context_spec.rb
|
112
|
+
- spec/errors_spec.rb
|
113
|
+
- spec/fauna_helper.rb
|
114
|
+
- spec/json_spec.rb
|
115
|
+
- spec/query_spec.rb
|
116
|
+
- spec/ref_spec.rb
|
117
|
+
- spec/setref_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/util_spec.rb
|
120
|
+
homepage: https://github.com/faunadb/faunadb-ruby
|
142
121
|
licenses:
|
143
|
-
-
|
122
|
+
- MPL-2.0
|
144
123
|
metadata: {}
|
145
124
|
post_install_message:
|
146
125
|
rdoc_options:
|
147
|
-
- --line-numbers
|
148
|
-
- --title
|
126
|
+
- "--line-numbers"
|
127
|
+
- "--title"
|
149
128
|
- Fauna
|
150
|
-
- --main
|
129
|
+
- "--main"
|
151
130
|
- README.md
|
152
131
|
require_paths:
|
153
132
|
- lib
|
154
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
155
134
|
requirements:
|
156
|
-
- -
|
135
|
+
- - ">="
|
157
136
|
- !ruby/object:Gem::Version
|
158
137
|
version: '0'
|
159
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
139
|
requirements:
|
161
|
-
- -
|
140
|
+
- - ">="
|
162
141
|
- !ruby/object:Gem::Version
|
163
|
-
version: '
|
142
|
+
version: '0'
|
164
143
|
requirements: []
|
165
|
-
rubyforge_project:
|
166
|
-
rubygems_version: 2.1
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.4.5.1
|
167
146
|
signing_key:
|
168
147
|
specification_version: 4
|
169
|
-
summary: Ruby client
|
148
|
+
summary: FaunaDB Ruby client
|
170
149
|
test_files:
|
171
|
-
-
|
172
|
-
-
|
173
|
-
-
|
174
|
-
-
|
175
|
-
-
|
176
|
-
-
|
177
|
-
-
|
178
|
-
-
|
150
|
+
- spec/util_spec.rb
|
151
|
+
- spec/context_spec.rb
|
152
|
+
- spec/client_logger_spec.rb
|
153
|
+
- spec/query_spec.rb
|
154
|
+
- spec/fauna_helper.rb
|
155
|
+
- spec/client_spec.rb
|
156
|
+
- spec/errors_spec.rb
|
157
|
+
- spec/setref_spec.rb
|
158
|
+
- spec/ref_spec.rb
|
159
|
+
- spec/spec_helper.rb
|
160
|
+
- spec/json_spec.rb
|
data/Manifest
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
CHANGELOG
|
2
|
-
Gemfile
|
3
|
-
LICENSE
|
4
|
-
Manifest
|
5
|
-
README.md
|
6
|
-
Rakefile
|
7
|
-
fauna.gemspec
|
8
|
-
lib/fauna.rb
|
9
|
-
lib/fauna/cache.rb
|
10
|
-
lib/fauna/client.rb
|
11
|
-
lib/fauna/connection.rb
|
12
|
-
lib/fauna/named_resource.rb
|
13
|
-
lib/fauna/rails.rb
|
14
|
-
lib/fauna/resource.rb
|
15
|
-
lib/fauna/set.rb
|
16
|
-
lib/fauna/util.rb
|
17
|
-
lib/tasks/fauna.rake
|
18
|
-
test/class_test.rb
|
19
|
-
test/client_test.rb
|
20
|
-
test/connection_test.rb
|
21
|
-
test/database_test.rb
|
22
|
-
test/query_test.rb
|
23
|
-
test/readme_test.rb
|
24
|
-
test/set_test.rb
|
25
|
-
test/test_helper.rb
|
data/lib/fauna/cache.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module Fauna
|
2
|
-
class NoContextError < StandardError
|
3
|
-
end
|
4
|
-
|
5
|
-
class Cache
|
6
|
-
attr_reader :connection
|
7
|
-
|
8
|
-
def initialize(connection)
|
9
|
-
fail ArgumentError, 'Connection cannot be nil' unless connection
|
10
|
-
@cache = {}
|
11
|
-
@connection = connection
|
12
|
-
end
|
13
|
-
|
14
|
-
def get(ref, query = {}, pagination = {})
|
15
|
-
res = @cache[ref]
|
16
|
-
res = @cache[res] if res.is_a? String # non-canonical refs point to their canonical refs.
|
17
|
-
|
18
|
-
if res.nil?
|
19
|
-
response = @connection.get(ref, query.merge(pagination))
|
20
|
-
update_cache(ref, response)
|
21
|
-
res = response['resource']
|
22
|
-
end
|
23
|
-
|
24
|
-
res
|
25
|
-
end
|
26
|
-
|
27
|
-
def post(ref, data)
|
28
|
-
res = @connection.post(ref, data)
|
29
|
-
update_cache(ref, res)
|
30
|
-
res['resource']
|
31
|
-
end
|
32
|
-
|
33
|
-
def put(ref, data)
|
34
|
-
res = @connection.put(ref, data)
|
35
|
-
return unless res['resource']
|
36
|
-
update_cache(ref, res)
|
37
|
-
res['resource']
|
38
|
-
end
|
39
|
-
|
40
|
-
def patch(ref, data)
|
41
|
-
res = @connection.patch(ref, data)
|
42
|
-
return unless res['resource']
|
43
|
-
update_cache(ref, res)
|
44
|
-
res['resource']
|
45
|
-
end
|
46
|
-
|
47
|
-
def delete(ref, data)
|
48
|
-
@connection.delete(ref, data)
|
49
|
-
@cache.delete(ref)
|
50
|
-
nil
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def update_cache(ref, res)
|
56
|
-
# FIXME: Implement set range caching
|
57
|
-
if res['resource']['class'] != 'resources' && res['resource']['class'] != 'events'
|
58
|
-
@cache[ref] = res['resource']['ref'] # store the non-canonical ref as a pointer to the real one.
|
59
|
-
@cache[res['resource']['ref']] = res['resource']
|
60
|
-
end
|
61
|
-
@cache.merge!(res['references'] || {})
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|