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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 417e86a661709395d59b9d89d3f543254dd17776
4
- data.tar.gz: 8b3e2c61b35797d40e02da7e3484e8c783604ddf
3
+ metadata.gz: 59bbd03578e238b4791ef3186d352d3645e6bb63
4
+ data.tar.gz: 5762944f1eb5349b9f1a5c306a7622ab89a3534e
5
5
  SHA512:
6
- metadata.gz: c36c66a54e94292bfc6ee380b87047e7c799bd5fb6d6602d4d79d1f3d21ada9a99479351c932546c241026782308515499c4eae2fd2d7c25000160ebea173226
7
- data.tar.gz: b8cce1b5d1b8f5963c2ad6cca237f3bbb74a7a3c588cb1a6032898aa2e469ec7592ab1b3fa4af34fd69382c544cf400caac308f77c4d00f5ea8a55a3fc72005c
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 "activesupport", "~> 4.0.0"
6
+ gem "activemodel", "~> 4.0.0"
3
7
  end
4
8
 
5
9
  appraise "rails-3.2" do
6
- gem "activesupport", "~> 3.2.0"
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 "activesupport", "~> 3.1.0"
15
+ gem "activemodel", "~> 3.1.0"
12
16
  gem "tzinfo", "~> 0.3"
13
17
  end
14
18
 
@@ -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
@@ -1,29 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cequel (1.2.1)
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.4)
12
- activesupport (= 4.0.4)
13
- builder (~> 3.1.0)
14
- activesupport (4.0.4)
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
- minitest (~> 4.2)
17
- multi_json (~> 1.3)
16
+ json (~> 1.7, >= 1.7.7)
17
+ minitest (~> 5.1)
18
18
  thread_safe (~> 0.1)
19
- tzinfo (~> 0.3.37)
19
+ tzinfo (~> 1.1)
20
20
  appraisal (0.5.2)
21
21
  bundler
22
22
  rake
23
23
  ast (1.1.0)
24
- atomic (1.1.16)
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 (4.7.5)
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.4)
58
+ psych (2.0.5)
62
59
  racc (1.4.11)
63
60
  rainbow (2.0.0)
64
- rake (10.1.1)
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.1)
286
- atomic (>= 1.1.7, < 2)
287
- thread_safe (0.3.1-java)
288
- atomic (>= 1.1.7, < 2)
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
- * Randy Meech
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.
@@ -1,6 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'delegate'
3
3
 
4
+ require 'active_support'
4
5
  require 'active_support/core_ext'
5
6
  require 'cql'
6
7
 
@@ -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
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Cequel
2
3
  module Record
3
4
  #
@@ -236,7 +236,7 @@ module Cequel
236
236
 
237
237
  # @private
238
238
  def hydrate(row)
239
- @attributes = row
239
+ init_attributes(row)
240
240
  hydrated!
241
241
  self
242
242
  end
@@ -38,7 +38,8 @@ module Cequel
38
38
 
39
39
  included do
40
40
  class_attribute :default_attributes, instance_writer: false
41
- self.default_attributes = {}
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.fetch(:default, []))
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.fetch(:default, ::Set[]))
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.fetch(:default, {}))
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
- @attributes = Marshal.load(Marshal.dump(
373
+ new_attributes = Marshal.load(Marshal.dump(
353
374
  default_attributes.except(*dynamic_defaults.keys)))
354
- dynamic_defaults.each { |name, p| @attributes[name] = p.call() }
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?
@@ -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
- watch_stack.watch_namespaces([Object])
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 << File.basename(file, '.rb').classify
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
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Cequel
3
3
  # The current version of the library
4
- VERSION = '1.2.1'
4
+ VERSION = '1.2.2'
5
5
  end
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require_relative 'spec_helper'
2
3
 
3
4
  describe Cequel::Record::Finders do
@@ -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 loaded' do
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 present' do
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.1
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-02 00:00:00.000000000 Z
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: '0.19'
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: '0.19'
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