cequel 1.2.1 → 1.2.2
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.
- checksums.yaml +4 -4
- data/Appraisals +7 -3
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +17 -21
- data/README.md +6 -1
- data/lib/cequel.rb +1 -0
- data/lib/cequel/record/collection.rb +1 -9
- data/lib/cequel/record/finders.rb +1 -0
- data/lib/cequel/record/persistence.rb +1 -1
- data/lib/cequel/record/properties.rb +28 -6
- data/lib/cequel/record/tasks.rb +11 -4
- data/lib/cequel/version.rb +1 -1
- data/spec/examples/record/finders_spec.rb +1 -0
- data/spec/examples/record/list_spec.rb +1 -1
- data/spec/examples/record/properties_spec.rb +32 -2
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 59bbd03578e238b4791ef3186d352d3645e6bb63
|
|
4
|
+
data.tar.gz: 5762944f1eb5349b9f1a5c306a7622ab89a3534e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 264d10150e444b24ce6b5f84cd010cd91467c1f5ff1a320d3ed9c9f9b2cf36281584609117e283fe79dc810b07a29a68838072127f0d78a4c5083a6358054a79
|
|
7
|
+
data.tar.gz: 0fcbb4eb278749a9f3800dd9fbe50e95645f484d3870fc2e8f6b7489533d6a25a77041244c3fb73e603c86c75dd5ce588b821aa25995414f0795118c9067c1eb
|
data/Appraisals
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
appraise "rails-4.1" do
|
|
2
|
+
gem "activemodel", "~> 4.1.0"
|
|
3
|
+
end
|
|
4
|
+
|
|
1
5
|
appraise "rails-4.0" do
|
|
2
|
-
gem "
|
|
6
|
+
gem "activemodel", "~> 4.0.0"
|
|
3
7
|
end
|
|
4
8
|
|
|
5
9
|
appraise "rails-3.2" do
|
|
6
|
-
gem "
|
|
10
|
+
gem "activemodel", "~> 3.2.0"
|
|
7
11
|
gem "tzinfo", "~> 0.3"
|
|
8
12
|
end
|
|
9
13
|
|
|
10
14
|
appraise "rails-3.1" do
|
|
11
|
-
gem "
|
|
15
|
+
gem "activemodel", "~> 3.1.0"
|
|
12
16
|
gem "tzinfo", "~> 0.3"
|
|
13
17
|
end
|
|
14
18
|
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## 1.2.2
|
|
2
|
+
|
|
3
|
+
* Support `:default` option for key columns
|
|
4
|
+
* Explicitly require `active_support` (Rails 4.1 compatibility)
|
|
5
|
+
* Detect namespaced models in subdirectories when running migrations
|
|
6
|
+
* Handle unset collection columns hydrated from database
|
|
7
|
+
|
|
1
8
|
## 1.2.1
|
|
2
9
|
|
|
3
10
|
* Remove `app_generators.orm` setting
|
data/Gemfile.lock
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
cequel (1.2.
|
|
4
|
+
cequel (1.2.2)
|
|
5
5
|
activemodel (>= 3.1, < 5.0)
|
|
6
6
|
cql-rb (~> 1.2)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activemodel (4.0
|
|
12
|
-
activesupport (= 4.0
|
|
13
|
-
builder (~> 3.1
|
|
14
|
-
activesupport (4.0
|
|
11
|
+
activemodel (4.1.0)
|
|
12
|
+
activesupport (= 4.1.0)
|
|
13
|
+
builder (~> 3.1)
|
|
14
|
+
activesupport (4.1.0)
|
|
15
15
|
i18n (~> 0.6, >= 0.6.9)
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
json (~> 1.7, >= 1.7.7)
|
|
17
|
+
minitest (~> 5.1)
|
|
18
18
|
thread_safe (~> 0.1)
|
|
19
|
-
tzinfo (~>
|
|
19
|
+
tzinfo (~> 1.1)
|
|
20
20
|
appraisal (0.5.2)
|
|
21
21
|
bundler
|
|
22
22
|
rake
|
|
23
23
|
ast (1.1.0)
|
|
24
|
-
|
|
25
|
-
atomic (1.1.16-java)
|
|
26
|
-
builder (3.1.4)
|
|
24
|
+
builder (3.2.2)
|
|
27
25
|
byebug (2.7.0)
|
|
28
26
|
columnize (~> 0.3)
|
|
29
27
|
debugger-linecache (~> 1.2)
|
|
@@ -43,8 +41,7 @@ GEM
|
|
|
43
41
|
json (1.8.1)
|
|
44
42
|
json (1.8.1-java)
|
|
45
43
|
method_source (0.8.2)
|
|
46
|
-
minitest (
|
|
47
|
-
multi_json (1.9.2)
|
|
44
|
+
minitest (5.3.2)
|
|
48
45
|
parser (2.1.7)
|
|
49
46
|
ast (~> 1.1)
|
|
50
47
|
slop (~> 3.4, >= 3.4.5)
|
|
@@ -58,10 +55,10 @@ GEM
|
|
|
58
55
|
method_source (~> 0.8)
|
|
59
56
|
slop (~> 3.4)
|
|
60
57
|
spoon (~> 0.0)
|
|
61
|
-
psych (2.0.
|
|
58
|
+
psych (2.0.5)
|
|
62
59
|
racc (1.4.11)
|
|
63
60
|
rainbow (2.0.0)
|
|
64
|
-
rake (10.
|
|
61
|
+
rake (10.2.2)
|
|
65
62
|
rspec (2.14.1)
|
|
66
63
|
rspec-core (~> 2.14.0)
|
|
67
64
|
rspec-expectations (~> 2.14.0)
|
|
@@ -282,11 +279,10 @@ GEM
|
|
|
282
279
|
slop (3.5.0)
|
|
283
280
|
spoon (0.0.4)
|
|
284
281
|
ffi
|
|
285
|
-
thread_safe (0.3.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
tzinfo (0.3.39)
|
|
282
|
+
thread_safe (0.3.3)
|
|
283
|
+
thread_safe (0.3.3-java)
|
|
284
|
+
tzinfo (1.1.0)
|
|
285
|
+
thread_safe (~> 0.1)
|
|
290
286
|
yard (0.8.7.4)
|
|
291
287
|
|
|
292
288
|
PLATFORMS
|
|
@@ -303,6 +299,6 @@ DEPENDENCIES
|
|
|
303
299
|
racc (~> 1.4)
|
|
304
300
|
rake (~> 10.1)
|
|
305
301
|
rspec (~> 2.0)
|
|
306
|
-
rubocop (~> 0.19)
|
|
302
|
+
rubocop (~> 0.19.0)
|
|
307
303
|
rubysl (~> 2.0)
|
|
308
304
|
yard (~> 0.6)
|
data/README.md
CHANGED
|
@@ -535,7 +535,12 @@ Cequel was written by:
|
|
|
535
535
|
* Keenan Brock
|
|
536
536
|
* Insoo Buzz Jung
|
|
537
537
|
* Louis Simoneau
|
|
538
|
-
*
|
|
538
|
+
* Peter Williams
|
|
539
|
+
* Kenneth Hoffman
|
|
540
|
+
* Antti Tapio
|
|
541
|
+
* Ilya Bazylchuk
|
|
542
|
+
* Dan Cardamore
|
|
543
|
+
* Kei Kusakari
|
|
539
544
|
|
|
540
545
|
Special thanks to [Brewster](https://www.brewster.com), which supported the 0.x
|
|
541
546
|
releases of Cequel.
|
data/lib/cequel.rb
CHANGED
|
@@ -120,8 +120,7 @@ module Cequel
|
|
|
120
120
|
protected
|
|
121
121
|
|
|
122
122
|
def __getobj__
|
|
123
|
-
model.__send__(:read_attribute, column_name)
|
|
124
|
-
model.__send__(:write_attribute, column_name, self.class.empty)
|
|
123
|
+
model.__send__(:read_attribute, column_name)
|
|
125
124
|
end
|
|
126
125
|
|
|
127
126
|
def __setobj__(obj)
|
|
@@ -185,13 +184,6 @@ module Cequel
|
|
|
185
184
|
NON_ATOMIC_MUTATORS
|
|
186
185
|
.each { |method| undef_method(method) if method_defined? method }
|
|
187
186
|
|
|
188
|
-
#
|
|
189
|
-
# @return [Array] an empty array
|
|
190
|
-
#
|
|
191
|
-
# @api private
|
|
192
|
-
#
|
|
193
|
-
def self.empty; []; end
|
|
194
|
-
|
|
195
187
|
#
|
|
196
188
|
# Set the value at a position or range of positions. This modification
|
|
197
189
|
# will be staged and persisted as an atomic list update when the record
|
|
@@ -38,7 +38,8 @@ module Cequel
|
|
|
38
38
|
|
|
39
39
|
included do
|
|
40
40
|
class_attribute :default_attributes, instance_writer: false
|
|
41
|
-
|
|
41
|
+
class_attribute :empty_attributes, instance_writer: false
|
|
42
|
+
self.default_attributes, self.empty_attributes = {}, {}
|
|
42
43
|
|
|
43
44
|
class <<self; alias_method :new_empty, :new; end
|
|
44
45
|
extend ConstructorMethods
|
|
@@ -102,6 +103,8 @@ module Cequel
|
|
|
102
103
|
fail ArgumentError, ":auto option only valid for UUID columns"
|
|
103
104
|
end
|
|
104
105
|
default = -> { Cequel.uuid } if options[:auto]
|
|
106
|
+
else
|
|
107
|
+
default = options[:default]
|
|
105
108
|
end
|
|
106
109
|
set_attribute_default(name, default)
|
|
107
110
|
end
|
|
@@ -146,7 +149,8 @@ module Cequel
|
|
|
146
149
|
#
|
|
147
150
|
def list(name, type, options = {})
|
|
148
151
|
def_collection_accessors(name, List)
|
|
149
|
-
set_attribute_default(name, options
|
|
152
|
+
set_attribute_default(name, options[:default])
|
|
153
|
+
set_empty_attribute(name) { [] }
|
|
150
154
|
end
|
|
151
155
|
|
|
152
156
|
#
|
|
@@ -164,7 +168,8 @@ module Cequel
|
|
|
164
168
|
#
|
|
165
169
|
def set(name, type, options = {})
|
|
166
170
|
def_collection_accessors(name, Set)
|
|
167
|
-
set_attribute_default(name, options
|
|
171
|
+
set_attribute_default(name, options[:default])
|
|
172
|
+
set_empty_attribute(name) { ::Set[] }
|
|
168
173
|
end
|
|
169
174
|
|
|
170
175
|
#
|
|
@@ -182,7 +187,8 @@ module Cequel
|
|
|
182
187
|
#
|
|
183
188
|
def map(name, key_type, value_type, options = {})
|
|
184
189
|
def_collection_accessors(name, Map)
|
|
185
|
-
set_attribute_default(name, options
|
|
190
|
+
set_attribute_default(name, options[:default])
|
|
191
|
+
set_empty_attribute(name) { {} }
|
|
186
192
|
end
|
|
187
193
|
|
|
188
194
|
private
|
|
@@ -230,6 +236,10 @@ module Cequel
|
|
|
230
236
|
def set_attribute_default(name, default)
|
|
231
237
|
default_attributes[name.to_sym] = default
|
|
232
238
|
end
|
|
239
|
+
|
|
240
|
+
def set_empty_attribute(name, &block)
|
|
241
|
+
empty_attributes[name.to_sym] = block
|
|
242
|
+
end
|
|
233
243
|
end
|
|
234
244
|
|
|
235
245
|
# @private
|
|
@@ -346,12 +356,24 @@ module Cequel
|
|
|
346
356
|
collection_proxies.delete(name)
|
|
347
357
|
end
|
|
348
358
|
|
|
359
|
+
def init_attributes(new_attributes)
|
|
360
|
+
@attributes = {}
|
|
361
|
+
new_attributes.each_pair do |name, value|
|
|
362
|
+
if value.nil?
|
|
363
|
+
value = empty_attributes.fetch(name.to_sym) { -> {} }.call
|
|
364
|
+
end
|
|
365
|
+
@attributes[name.to_sym] = value
|
|
366
|
+
end
|
|
367
|
+
@attributes
|
|
368
|
+
end
|
|
369
|
+
|
|
349
370
|
def initialize_new_record(attributes = {})
|
|
350
371
|
dynamic_defaults = default_attributes
|
|
351
372
|
.select { |name, value| value.is_a?(Proc) }
|
|
352
|
-
|
|
373
|
+
new_attributes = Marshal.load(Marshal.dump(
|
|
353
374
|
default_attributes.except(*dynamic_defaults.keys)))
|
|
354
|
-
dynamic_defaults.each { |name, p|
|
|
375
|
+
dynamic_defaults.each { |name, p| new_attributes[name] = p.call }
|
|
376
|
+
init_attributes(new_attributes)
|
|
355
377
|
|
|
356
378
|
@new_record = true
|
|
357
379
|
yield self if block_given?
|
data/lib/cequel/record/tasks.rb
CHANGED
|
@@ -19,14 +19,19 @@ namespace :cequel do
|
|
|
19
19
|
task :migrate => :environment do
|
|
20
20
|
watch_stack = ActiveSupport::Dependencies::WatchStack.new
|
|
21
21
|
|
|
22
|
+
migration_table_names = Set[]
|
|
23
|
+
models_dir_path = "#{Rails.root.join('app', 'models')}/"
|
|
22
24
|
Dir.glob(Rails.root.join('app', 'models', '**', '*.rb')).each do |file|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
watch_namespaces = ["Object"]
|
|
26
|
+
model_file_name = file.sub(/^#{Regexp.escape(models_dir_path)}/, "")
|
|
27
|
+
dirname = File.dirname(model_file_name)
|
|
28
|
+
watch_namespaces << dirname.classify unless dirname == "."
|
|
29
|
+
watch_stack.watch_namespaces(watch_namespaces)
|
|
25
30
|
require_dependency(file)
|
|
26
31
|
|
|
27
32
|
new_constants = watch_stack.new_constants
|
|
28
33
|
if new_constants.empty?
|
|
29
|
-
new_constants <<
|
|
34
|
+
new_constants << model_file_name.sub(/\.rb$/, "").classify
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
new_constants.each do |class_name|
|
|
@@ -34,8 +39,10 @@ namespace :cequel do
|
|
|
34
39
|
clazz = class_name.constantize
|
|
35
40
|
rescue NameError # rubocop:disable HandleExceptions
|
|
36
41
|
else
|
|
37
|
-
if clazz.ancestors.include?(Cequel::Record)
|
|
42
|
+
if clazz.ancestors.include?(Cequel::Record) &&
|
|
43
|
+
!migration_table_names.include?(clazz.table_name.to_sym)
|
|
38
44
|
clazz.synchronize_schema
|
|
45
|
+
migration_table_names << clazz.table_name.to_sym
|
|
39
46
|
puts "Synchronized schema for #{class_name}"
|
|
40
47
|
end
|
|
41
48
|
end
|
data/lib/cequel/version.rb
CHANGED
|
@@ -65,7 +65,7 @@ describe Cequel::Record::List do
|
|
|
65
65
|
subject[:tags].should == %w(one two four five)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
it 'should add new items in memory when
|
|
68
|
+
it 'should load itself and then add new items in memory when unloaded' do
|
|
69
69
|
unloaded_post.tags << 'four' << 'five'
|
|
70
70
|
expect(unloaded_post.tags).to eq(%w(one two four five))
|
|
71
71
|
end
|
|
@@ -75,6 +75,13 @@ describe Cequel::Record::Properties do
|
|
|
75
75
|
expect(Post.new.tags).to eq([])
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
+
it 'should have empty list column value if unset in database' do
|
|
79
|
+
uniq_key = SecureRandom.uuid
|
|
80
|
+
Post.create! permalink: uniq_key
|
|
81
|
+
expect(Post[uniq_key].tags).to eq([])
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
|
|
78
85
|
it 'should provide accessor for set column' do
|
|
79
86
|
expect(Post.new { |post| post.categories = Set['Big Data', 'Cassandra'] }
|
|
80
87
|
.categories).to eq(Set['Big Data', 'Cassandra'])
|
|
@@ -90,10 +97,16 @@ describe Cequel::Record::Properties do
|
|
|
90
97
|
.to eq(Set['1', '2', '3'])
|
|
91
98
|
end
|
|
92
99
|
|
|
93
|
-
it 'should have empty set column value if
|
|
100
|
+
it 'should have empty set column value if not explicitly set' do
|
|
94
101
|
expect(Post.new.categories).to eq(Set[])
|
|
95
102
|
end
|
|
96
103
|
|
|
104
|
+
it 'should handle saved records with unspecified set properties' do
|
|
105
|
+
uuid = SecureRandom.uuid
|
|
106
|
+
Post.create!(permalink: uuid)
|
|
107
|
+
expect(Post[uuid].categories).to eq(::Set[])
|
|
108
|
+
end
|
|
109
|
+
|
|
97
110
|
it 'should provide accessor for map column' do
|
|
98
111
|
expect(Post.new { |post| post.shares = {'facebook' => 1, 'twitter' => 2}}
|
|
99
112
|
.shares).to eq({'facebook' => 1, 'twitter' => 2})
|
|
@@ -112,17 +125,29 @@ describe Cequel::Record::Properties do
|
|
|
112
125
|
it 'should set map column to empty hash by default' do
|
|
113
126
|
expect(Post.new.shares).to eq({})
|
|
114
127
|
end
|
|
128
|
+
|
|
129
|
+
it 'should handle saved records with unspecified map properties' do
|
|
130
|
+
uuid = SecureRandom.uuid
|
|
131
|
+
Post.create!(permalink: uuid)
|
|
132
|
+
expect(Post[uuid].shares).to eq({})
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
115
136
|
end
|
|
116
137
|
|
|
117
138
|
describe 'configured property defaults' do
|
|
118
139
|
model :Post do
|
|
119
|
-
key :permalink, :text
|
|
140
|
+
key :permalink, :text, :default => 'new_permalink'
|
|
120
141
|
column :title, :text, :default => 'New Post'
|
|
121
142
|
list :tags, :text, :default => ['new']
|
|
122
143
|
set :categories, :text, :default => Set['Big Data']
|
|
123
144
|
map :shares, :text, :int, :default => {'facebook' => 0}
|
|
124
145
|
end
|
|
125
146
|
|
|
147
|
+
it 'should respect default for keys' do
|
|
148
|
+
Post.new.permalink.should == 'new_permalink'
|
|
149
|
+
end
|
|
150
|
+
|
|
126
151
|
it 'should respect default for data column' do
|
|
127
152
|
Post.new.title.should == 'New Post'
|
|
128
153
|
end
|
|
@@ -143,6 +168,7 @@ describe Cequel::Record::Properties do
|
|
|
143
168
|
describe 'dynamic property generation' do
|
|
144
169
|
model :Post do
|
|
145
170
|
key :id, :uuid, auto: true
|
|
171
|
+
key :subid, :text, default: -> { "subid #{1+1}" }
|
|
146
172
|
column :title, :text, default: -> { "Post #{Date.today}" }
|
|
147
173
|
end
|
|
148
174
|
|
|
@@ -159,6 +185,10 @@ describe Cequel::Record::Properties do
|
|
|
159
185
|
end.to raise_error(ArgumentError)
|
|
160
186
|
end
|
|
161
187
|
|
|
188
|
+
it 'should run default proc on keys' do
|
|
189
|
+
Post.new.subid.should == "subid #{1+1}"
|
|
190
|
+
end
|
|
191
|
+
|
|
162
192
|
it 'should run default proc' do
|
|
163
193
|
Post.new.title.should == "Post #{Date.today}"
|
|
164
194
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cequel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mat Brown
|
|
@@ -13,10 +13,12 @@ authors:
|
|
|
13
13
|
- Kenneth Hoffman
|
|
14
14
|
- Antti Tapio
|
|
15
15
|
- Ilya Bazylchuk
|
|
16
|
+
- Dan Cardamore
|
|
17
|
+
- Kei Kusakari
|
|
16
18
|
autorequire:
|
|
17
19
|
bindir: bin
|
|
18
20
|
cert_chain: []
|
|
19
|
-
date: 2014-04-
|
|
21
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
|
20
22
|
dependencies:
|
|
21
23
|
- !ruby/object:Gem::Dependency
|
|
22
24
|
name: activemodel
|
|
@@ -114,14 +116,14 @@ dependencies:
|
|
|
114
116
|
requirements:
|
|
115
117
|
- - "~>"
|
|
116
118
|
- !ruby/object:Gem::Version
|
|
117
|
-
version:
|
|
119
|
+
version: 0.19.0
|
|
118
120
|
type: :development
|
|
119
121
|
prerelease: false
|
|
120
122
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
123
|
requirements:
|
|
122
124
|
- - "~>"
|
|
123
125
|
- !ruby/object:Gem::Version
|
|
124
|
-
version:
|
|
126
|
+
version: 0.19.0
|
|
125
127
|
description: |
|
|
126
128
|
Cequel is an ActiveRecord-like domain model layer for Cassandra that exposes
|
|
127
129
|
the robust data modeling capabilities of CQL3, including parent-child
|