whi-cassie 1.2.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/continuous_integration.yml +30 -14
- data/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/Appraisals +4 -0
- data/Gemfile +1 -1
- data/HISTORY.md +13 -0
- data/VERSION +1 -1
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/activemodel_4.gemfile +1 -1
- data/gemfiles/activemodel_5.gemfile +1 -1
- data/gemfiles/activemodel_6.gemfile +1 -1
- data/gemfiles/activemodel_7.gemfile +14 -0
- data/lib/cassie/model.rb +32 -1
- data/lib/cassie.rb +14 -7
- data/spec/cassie/model_spec.rb +24 -1
- data/spec/spec_helper.rb +1 -1
- data/whi-cassie.gemspec +1 -0
- metadata +23 -7
- data/Gemfile.lock +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c87e681cda4e500a2f9cb34eee05a806525cce81305f2732ff6b33bd9c13170
|
4
|
+
data.tar.gz: 4edfe67aa1bba47bac102cd3b1b181240bab73469e45d16c0a1cc922467c74e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b1e1b1e0f674740d0f217a608ae1f024fff3c2529b6a29028b46cb6cbbbc6a077c2dc0b4fb8e2c0b0fa5dd6fa6cc233df74c76ce302378a738583c2fa3ea6a6
|
7
|
+
data.tar.gz: e192c9f23cd323468b47dbc20762e63dc891c6837e6863eb56ea2abee7611d5b50289795dc9da5b6061c9b62495833df5c61599ff7feec15ca00a31a89dbee83
|
@@ -13,33 +13,52 @@ env:
|
|
13
13
|
BUNDLE_JOBS: 3
|
14
14
|
BUNDLE_RETRY: 3
|
15
15
|
jobs:
|
16
|
+
standard:
|
17
|
+
name: StandardRB
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
steps:
|
20
|
+
- name: checkout
|
21
|
+
uses: actions/checkout@v2
|
22
|
+
- name: set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: 3.0
|
26
|
+
- name: install dependencies
|
27
|
+
run: bundle install
|
28
|
+
- name: standardrb
|
29
|
+
if: matrix.job == 'standardrb'
|
30
|
+
run: bundle exec rake standard
|
31
|
+
|
16
32
|
specs:
|
17
33
|
name: ${{ matrix.job }} ruby-${{ matrix.ruby }} ${{ matrix.activemodel && format('activemodel-{0}', matrix.activemodel) }} cassandra-${{ matrix.cassandra_version }}
|
18
34
|
runs-on: ubuntu-latest
|
19
35
|
services:
|
20
36
|
cassandra:
|
21
|
-
image: cassandra:${{ matrix.cassandra_version }}
|
37
|
+
image: cassandra:${{ matrix.cassandra_version || 'latest' }}
|
22
38
|
ports:
|
23
39
|
- 9042:9042
|
24
40
|
strategy:
|
25
41
|
fail-fast: false
|
26
42
|
matrix:
|
27
|
-
ruby: [
|
28
|
-
activemodel: [
|
43
|
+
ruby: ["3.1"]
|
44
|
+
activemodel: ["original"]
|
29
45
|
job: [rspec]
|
30
|
-
cassandra_version: ["
|
46
|
+
cassandra_version: ["latest"]
|
31
47
|
include:
|
32
|
-
- ruby: 2.6
|
33
|
-
activemodel: 5
|
48
|
+
- ruby: "2.6"
|
49
|
+
activemodel: "5"
|
34
50
|
job: rspec
|
35
51
|
cassandra_version: "3"
|
36
|
-
- ruby: 2.4
|
37
|
-
activemodel: 4
|
52
|
+
- ruby: "2.4"
|
53
|
+
activemodel: "4"
|
38
54
|
job: rspec
|
39
55
|
cassandra_version: "2"
|
40
|
-
- ruby: 2.7
|
41
|
-
|
42
|
-
|
56
|
+
- ruby: "2.7"
|
57
|
+
activemodel: "6"
|
58
|
+
job: rspec
|
59
|
+
- ruby: "3.0"
|
60
|
+
activemodel: "7"
|
61
|
+
job: rspec
|
43
62
|
steps:
|
44
63
|
- name: checkout
|
45
64
|
uses: actions/checkout@v2
|
@@ -58,6 +77,3 @@ jobs:
|
|
58
77
|
- name: specs
|
59
78
|
if: matrix.job == 'rspec'
|
60
79
|
run: bundle exec rake spec
|
61
|
-
- name: standardrb
|
62
|
-
if: matrix.job == 'standardrb'
|
63
|
-
run: bundle exec rake standard
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.2
|
data/Appraisals
CHANGED
data/Gemfile
CHANGED
data/HISTORY.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 1.3.2
|
2
|
+
|
3
|
+
* Improved synchronization on reconnect logic.
|
4
|
+
|
5
|
+
## 1.3.1
|
6
|
+
|
7
|
+
* Remove automatic reconnect on I/O errors.
|
8
|
+
* Handle race condition on connecting when already connected.
|
9
|
+
|
10
|
+
## 1.3.0
|
11
|
+
|
12
|
+
* Add update, update!, primary_key, and reload methods to models.
|
13
|
+
|
1
14
|
## 1.2.0
|
2
15
|
|
3
16
|
* Update schema queries to support Cassandra 3.x+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2
|
1
|
+
1.3.2
|
data/lib/cassie/model.rb
CHANGED
@@ -451,7 +451,7 @@ module Cassie::Model
|
|
451
451
|
elsif type_class == Cassandra::Types::Set
|
452
452
|
Set.new(value)
|
453
453
|
elsif type_class == Cassandra::Types::Map
|
454
|
-
|
454
|
+
value.to_h
|
455
455
|
else
|
456
456
|
type_class.new(value)
|
457
457
|
end
|
@@ -531,6 +531,18 @@ module Cassie::Model
|
|
531
531
|
end
|
532
532
|
end
|
533
533
|
|
534
|
+
# Update a record with the specified attributes. Returns false the record is invalid.
|
535
|
+
def update(values)
|
536
|
+
self.attributes = values
|
537
|
+
save
|
538
|
+
end
|
539
|
+
|
540
|
+
# Update a record with the specified attributes and raise an error if it is invalid.
|
541
|
+
def update!(values)
|
542
|
+
self.attributes = values
|
543
|
+
save!
|
544
|
+
end
|
545
|
+
|
534
546
|
# Returns a hash of column to values. Column names will be symbols.
|
535
547
|
def attributes
|
536
548
|
hash = {}
|
@@ -540,6 +552,25 @@ module Cassie::Model
|
|
540
552
|
hash
|
541
553
|
end
|
542
554
|
|
555
|
+
# Mass set attributes from a hash.
|
556
|
+
def attributes=(values)
|
557
|
+
values.each do |name, value|
|
558
|
+
send("#{name}=", value)
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
# Returns a hash representing the primary key value.
|
563
|
+
def primary_key
|
564
|
+
self.class.primary_key.each_with_object({}) { |name, hash|
|
565
|
+
hash[name] = send(name)
|
566
|
+
}
|
567
|
+
end
|
568
|
+
|
569
|
+
# Reloads the record in memory.
|
570
|
+
def reload
|
571
|
+
self.class.find(primary_key)
|
572
|
+
end
|
573
|
+
|
543
574
|
# Subclasses can override this method to provide a TTL on the persisted record.
|
544
575
|
def persistence_ttl
|
545
576
|
nil
|
data/lib/cassie.rb
CHANGED
@@ -102,8 +102,10 @@ class Cassie
|
|
102
102
|
cluster = Cassandra.cluster(cluster_config)
|
103
103
|
logger&.info("Cassie.connect with #{config.sanitized_cluster} in #{((Time.now - start_time) * 1000).round}ms")
|
104
104
|
@monitor.synchronize do
|
105
|
-
@session
|
106
|
-
|
105
|
+
unless @session
|
106
|
+
@session = cluster.connect(config.default_keyspace)
|
107
|
+
@prepared_statements = {}
|
108
|
+
end
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
@@ -126,7 +128,9 @@ class Cassie
|
|
126
128
|
# like passenger or unicorn you should call this method after forking.
|
127
129
|
def reconnect
|
128
130
|
disconnect
|
129
|
-
|
131
|
+
@monitor.synchronize do
|
132
|
+
connect unless connected?
|
133
|
+
end
|
130
134
|
end
|
131
135
|
|
132
136
|
# Prepare a CQL statement for repeate execution. Prepared statements
|
@@ -307,9 +311,6 @@ class Cassie
|
|
307
311
|
end
|
308
312
|
|
309
313
|
session.execute(statement, options || {})
|
310
|
-
rescue Cassandra::Errors::IOError => e
|
311
|
-
disconnect
|
312
|
-
raise e
|
313
314
|
ensure
|
314
315
|
if statement.is_a?(Cassandra::Statement) && !subscribers.empty?
|
315
316
|
payload = Message.new(statement, options, Time.now - start_time)
|
@@ -330,7 +331,13 @@ class Cassie
|
|
330
331
|
end
|
331
332
|
|
332
333
|
def session
|
333
|
-
|
334
|
+
unless connected?
|
335
|
+
# Check again inside the monitor lock so we don't get in a race condition
|
336
|
+
# where another thread has already established the connection.
|
337
|
+
@monitor.synchronize do
|
338
|
+
connect unless connected?
|
339
|
+
end
|
340
|
+
end
|
334
341
|
@session
|
335
342
|
end
|
336
343
|
|
data/spec/cassie/model_spec.rb
CHANGED
@@ -133,7 +133,7 @@ describe Cassie::Model do
|
|
133
133
|
describe "batch" do
|
134
134
|
it "should delegate to Cassie.batch using the write consistency" do
|
135
135
|
expect(Cassie::Thing.connection).to be_a(Cassie)
|
136
|
-
expect(Cassie::Thing.connection).to receive(:batch).
|
136
|
+
expect(Cassie::Thing.connection).to receive(:batch).and_call_original
|
137
137
|
Cassie::Thing.batch {}
|
138
138
|
end
|
139
139
|
end
|
@@ -142,11 +142,15 @@ describe Cassie::Model do
|
|
142
142
|
it "should get and set attributes" do
|
143
143
|
record = Cassie::Thing.new(owner: 1, id: 2, val: "foo")
|
144
144
|
expect(record.attributes).to eq({owner: 1, id: 2, val: "foo"})
|
145
|
+
record.attributes = {owner: 2, id: 3, val: "bar"}
|
146
|
+
expect(record.attributes).to eq({owner: 2, id: 3, val: "bar"})
|
145
147
|
end
|
146
148
|
|
147
149
|
it "should get and set attributes using human readable names" do
|
148
150
|
record = Cassie::Thing.new(owner: 1, identifier: 2, value: "foo")
|
149
151
|
expect(record.attributes).to eq({owner: 1, id: 2, val: "foo"})
|
152
|
+
record.attributes = {owner: 2, identifier: 3, val: "bar"}
|
153
|
+
expect(record.attributes).to eq({owner: 2, id: 3, val: "bar"})
|
150
154
|
end
|
151
155
|
end
|
152
156
|
|
@@ -194,6 +198,25 @@ describe Cassie::Model do
|
|
194
198
|
end
|
195
199
|
end
|
196
200
|
|
201
|
+
describe "update" do
|
202
|
+
it "should set attributes and save" do
|
203
|
+
record = Cassie::Thing.create(owner: 1, id: 2, val: "foo")
|
204
|
+
record.update(owner: 2)
|
205
|
+
record.reload
|
206
|
+
expect(record.owner).to eq 2
|
207
|
+
record.update!(owner: 3)
|
208
|
+
record.reload
|
209
|
+
expect(record.owner).to eq 3
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "primary_key" do
|
214
|
+
it "should return the primary key as a hash" do
|
215
|
+
record = Cassie::Thing.create(owner: 1, id: 2, val: "foo")
|
216
|
+
expect(record.primary_key).to eq({owner: 1, id: 2})
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
197
220
|
describe "destroy" do
|
198
221
|
it "should delete a record from Cassandra calling any destroy callbacks" do
|
199
222
|
Cassie::Thing.create(owner: 1, id: 2, val: "foo")
|
data/spec/spec_helper.rb
CHANGED
data/whi-cassie.gemspec
CHANGED
@@ -19,5 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.required_ruby_version = ">= 2.4"
|
20
20
|
spec.add_dependency("cassandra-driver", "~>3.0")
|
21
21
|
spec.add_dependency("activemodel", ">=4.0")
|
22
|
+
spec.add_dependency("sorted_set")
|
22
23
|
spec.add_development_dependency "bundler", "~>2.0"
|
23
24
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whi-cassie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- We Heart It
|
8
8
|
- Brian Durand
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cassandra-driver
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '4.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: sorted_set
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: bundler
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,18 +77,20 @@ files:
|
|
63
77
|
- ".github/dependabot.yml"
|
64
78
|
- ".github/workflows/continuous_integration.yml"
|
65
79
|
- ".gitignore"
|
80
|
+
- ".ruby-version"
|
66
81
|
- ".standard.yml"
|
67
82
|
- Appraisals
|
68
83
|
- Gemfile
|
69
|
-
- Gemfile.lock
|
70
84
|
- HISTORY.md
|
71
85
|
- MIT-LICENSE
|
72
86
|
- README.md
|
73
87
|
- Rakefile
|
74
88
|
- VERSION
|
89
|
+
- gemfiles/.bundle/config
|
75
90
|
- gemfiles/activemodel_4.gemfile
|
76
91
|
- gemfiles/activemodel_5.gemfile
|
77
92
|
- gemfiles/activemodel_6.gemfile
|
93
|
+
- gemfiles/activemodel_7.gemfile
|
78
94
|
- lib/cassie.rb
|
79
95
|
- lib/cassie/config.rb
|
80
96
|
- lib/cassie/model.rb
|
@@ -96,7 +112,7 @@ homepage: https://github.com/weheartit/cassie
|
|
96
112
|
licenses:
|
97
113
|
- MIT
|
98
114
|
metadata: {}
|
99
|
-
post_install_message:
|
115
|
+
post_install_message:
|
100
116
|
rdoc_options: []
|
101
117
|
require_paths:
|
102
118
|
- lib
|
@@ -111,8 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
127
|
- !ruby/object:Gem::Version
|
112
128
|
version: '0'
|
113
129
|
requirements: []
|
114
|
-
rubygems_version: 3.
|
115
|
-
signing_key:
|
130
|
+
rubygems_version: 3.2.22
|
131
|
+
signing_key:
|
116
132
|
specification_version: 4
|
117
133
|
summary: Simple object mapper for Cassandra data tables specifically designed to work
|
118
134
|
with the limitations and strengths of Cassandra.
|
data/Gemfile.lock
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
whi-cassie (1.2.0)
|
5
|
-
activemodel (>= 4.0)
|
6
|
-
cassandra-driver (~> 3.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (6.0.3.4)
|
12
|
-
activesupport (= 6.0.3.4)
|
13
|
-
activesupport (6.0.3.4)
|
14
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
-
i18n (>= 0.7, < 2)
|
16
|
-
minitest (~> 5.1)
|
17
|
-
tzinfo (~> 1.1)
|
18
|
-
zeitwerk (~> 2.2, >= 2.2.2)
|
19
|
-
appraisal (2.3.0)
|
20
|
-
bundler
|
21
|
-
rake
|
22
|
-
thor (>= 0.14.0)
|
23
|
-
ast (2.4.1)
|
24
|
-
cassandra-driver (3.2.5)
|
25
|
-
ione (~> 1.2)
|
26
|
-
concurrent-ruby (1.1.7)
|
27
|
-
diff-lcs (1.4.4)
|
28
|
-
i18n (1.8.5)
|
29
|
-
concurrent-ruby (~> 1.0)
|
30
|
-
ione (1.2.4)
|
31
|
-
minitest (5.14.2)
|
32
|
-
parallel (1.19.2)
|
33
|
-
parser (2.7.2.0)
|
34
|
-
ast (~> 2.4.1)
|
35
|
-
rainbow (3.0.0)
|
36
|
-
rake (13.0.1)
|
37
|
-
regexp_parser (1.8.2)
|
38
|
-
rexml (3.2.4)
|
39
|
-
rspec (3.9.0)
|
40
|
-
rspec-core (~> 3.9.0)
|
41
|
-
rspec-expectations (~> 3.9.0)
|
42
|
-
rspec-mocks (~> 3.9.0)
|
43
|
-
rspec-core (3.9.3)
|
44
|
-
rspec-support (~> 3.9.3)
|
45
|
-
rspec-expectations (3.9.3)
|
46
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.9.0)
|
48
|
-
rspec-mocks (3.9.1)
|
49
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.9.0)
|
51
|
-
rspec-support (3.9.4)
|
52
|
-
rubocop (1.0.0)
|
53
|
-
parallel (~> 1.10)
|
54
|
-
parser (>= 2.7.1.5)
|
55
|
-
rainbow (>= 2.2.2, < 4.0)
|
56
|
-
regexp_parser (>= 1.8)
|
57
|
-
rexml
|
58
|
-
rubocop-ast (>= 0.6.0)
|
59
|
-
ruby-progressbar (~> 1.7)
|
60
|
-
unicode-display_width (>= 1.4.0, < 2.0)
|
61
|
-
rubocop-ast (1.1.0)
|
62
|
-
parser (>= 2.7.1.5)
|
63
|
-
rubocop-performance (1.8.1)
|
64
|
-
rubocop (>= 0.87.0)
|
65
|
-
rubocop-ast (>= 0.4.0)
|
66
|
-
ruby-progressbar (1.10.1)
|
67
|
-
standard (0.8.1)
|
68
|
-
rubocop (= 1.0.0)
|
69
|
-
rubocop-performance (= 1.8.1)
|
70
|
-
thor (1.0.1)
|
71
|
-
thread_safe (0.3.6)
|
72
|
-
tzinfo (1.2.7)
|
73
|
-
thread_safe (~> 0.1)
|
74
|
-
unicode-display_width (1.7.0)
|
75
|
-
zeitwerk (2.4.0)
|
76
|
-
|
77
|
-
PLATFORMS
|
78
|
-
ruby
|
79
|
-
|
80
|
-
DEPENDENCIES
|
81
|
-
appraisal
|
82
|
-
bundler (~> 2.0)
|
83
|
-
rake
|
84
|
-
rspec
|
85
|
-
standard (~> 0.8.1)
|
86
|
-
whi-cassie!
|
87
|
-
|
88
|
-
BUNDLED WITH
|
89
|
-
2.1.4
|