gotime-cassandra_object 4.10.0 → 4.10.1

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: 7073b42de70860d98b730e0bdc70bea709b52303
4
- data.tar.gz: e074884e886d5564c546dc039b9582d0b8029514
3
+ metadata.gz: a094a6b0709d5666b254585cf07f2e8889abf318
4
+ data.tar.gz: f13ccf6c6431c0f576110ef956b18eb809367bd5
5
5
  SHA512:
6
- metadata.gz: f3a6fc60a3b36f91ca85fcd053a8d6578421831b1ff1f184a504ce5fd9991434573acb2f66e0021699389e445fb06c543ba8a60d7cf734f5aefc337343c321bc
7
- data.tar.gz: d7504256963ff601ade664dbd8fdf7da672adaef16d5017aeda6e917892f6eef7243f611c55a8aa7ae6812c754649596c1fb6189372bc604e65fe381eda06836
6
+ metadata.gz: b6fa0ffb1d1c554e906be4adf20ae4c1a0dac7148fa7bff4d15f9574750946f2f41d4833b86058f0d62825529a4a5d6f1e24dc19c8912afd86d2185ac48bbcd5
7
+ data.tar.gz: 5060c16d39315b8cc1c98855582450715ac3e30162ab9328a148e2fac2bdc6b401f44fd29fbbc2df2b66864fb5b08187c08079a48042f477dea4f9ea9793be94
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '4.10.0'
5
+ s.version = '4.10.1'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
@@ -8,7 +8,13 @@ module CassandraObject
8
8
 
9
9
  module ClassMethods
10
10
  def remove(id)
11
- execute_batchable_cql "DELETE FROM #{column_family}#{write_option_string} WHERE KEY = ?", id
11
+ statement = "DELETE FROM #{column_family}#{write_option_string} WHERE "
12
+ if id.is_a?(Array)
13
+ statement += "KEY IN (?)"
14
+ else
15
+ statement += "KEY = ?"
16
+ end
17
+ execute_batchable_cql statement, id
12
18
  end
13
19
 
14
20
  def delete_all
@@ -1,6 +1,40 @@
1
1
  module CassandraObject
2
2
  module Types
3
3
  class JsonType < BaseType
4
+ class DirtyHash < Hash
5
+ attr_accessor :record, :name, :options
6
+ def initialize(record, name, hash, options)
7
+ @record = record
8
+ @name = name.to_s
9
+ @options = options
10
+
11
+ self.merge!(hash)
12
+ @init_hash = self.hash
13
+ @init_value = hash
14
+ end
15
+
16
+ def []=(obj, val)
17
+ modifying do super end
18
+ end
19
+
20
+ def delete(obj)
21
+ modifying do super end
22
+ end
23
+
24
+ private
25
+ def modifying
26
+ result = yield
27
+
28
+ if !record.changed_attributes.key?(name) && @init_hash != self.hash
29
+ record.changed_attributes[name] = @init_value
30
+ end
31
+
32
+ record.send("#{name}=", self)
33
+
34
+ result
35
+ end
36
+ end
37
+
4
38
  def encode(hash)
5
39
  ActiveSupport::JSON.encode(hash)
6
40
  end
@@ -8,6 +42,11 @@ module CassandraObject
8
42
  def decode(str)
9
43
  ActiveSupport::JSON.decode(str)
10
44
  end
45
+
46
+ def wrap(record, name, value)
47
+ DirtyHash.new(record, name, Hash(value), options)
48
+ end
49
+
11
50
  end
12
51
  end
13
52
  end
@@ -184,4 +184,40 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
184
184
  klass = Class.new { include CassandraObject::Persistence }
185
185
  assert_equal %w{'a' 'b'}, klass.__send__(:quote_columns, %w{a b})
186
186
  end
187
+
188
+ test 'remove' do
189
+ klass = temp_object do
190
+ string :name
191
+ end
192
+
193
+ record = klass.new(name: 'cool')
194
+ record.save!
195
+
196
+ id = record.id
197
+ assert_equal id, klass.find(id).id
198
+
199
+ klass.remove(id)
200
+
201
+ assert_raise CassandraObject::RecordNotFound do
202
+ klass.find(id)
203
+ end
204
+ end
205
+
206
+ test 'remove multiple' do
207
+ klass = temp_object do
208
+ string :name
209
+ end
210
+
211
+ ids = []
212
+ (1..10).each do
213
+ record = klass.new(name: 'cool')
214
+ record.save!
215
+ ids << record.id
216
+ end
217
+
218
+ klass.remove(ids)
219
+
220
+ assert_equal [], klass.find(ids)
221
+ end
222
+
187
223
  end
@@ -9,4 +9,69 @@ class CassandraObject::Types::JsonTypeTest < CassandraObject::Types::TestCase
9
9
  test 'decode' do
10
10
  assert_equal({'a' => 'b'}, coder.decode({'a' => 'b'}.to_json))
11
11
  end
12
+
13
+ test 'setting marks dirty' do
14
+ record = temp_object do
15
+ string :name
16
+ json :stuff
17
+
18
+ end.new name: 'abcd', stuff: Hash[a: 1, b: 2]
19
+
20
+ record.save!
21
+ assert !record.stuff_changed?
22
+
23
+ record.stuff[:c] = 3
24
+
25
+ assert record.stuff_changed?
26
+ assert_equal Hash[a: 1, b: 2, c: 3], record.stuff
27
+ end
28
+
29
+ test 'hash change marks dirty' do
30
+ record = temp_object do
31
+ string :name
32
+ json :stuff
33
+
34
+ end.new name: 'abcd', stuff: Hash[a: 1, b: 2, v: {}]
35
+
36
+ record.save!
37
+ assert !record.stuff_changed?
38
+
39
+ record.stuff[:v][:data] = 69
40
+ record.stuff[:v] = record.stuff[:v]
41
+
42
+ assert record.stuff_changed?
43
+ assert_equal Hash[a: 1, b: 2, v: Hash[data: 69]], record.stuff
44
+ end
45
+
46
+ test 'hash no change does not dirty' do
47
+ record = temp_object do
48
+ string :name
49
+ json :stuff
50
+
51
+ end.new name: 'abcd', stuff: Hash[a: 1, b: 2, v: {data: 69}]
52
+
53
+ record.save!
54
+ assert !record.stuff_changed?
55
+
56
+ record.stuff[:v][:data] = 69
57
+ record.stuff[:v] = record.stuff[:v]
58
+
59
+ assert !record.stuff_changed?
60
+ assert_equal Hash[a: 1, b: 2, v: Hash[data: 69]], record.stuff
61
+ end
62
+
63
+ test 'delete marks dirty' do
64
+ record = temp_object do
65
+ string :name
66
+ json :stuff
67
+
68
+ end.new name: 'abcd', stuff: Hash[a: 1, b: 2]
69
+
70
+ record.stuff.delete :b
71
+
72
+ assert record.stuff_changed?
73
+ assert_equal Hash[a: 1], record.stuff
74
+ end
75
+
76
+
12
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotime-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.10.0
4
+ version: 4.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Koziarski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: 1.3.5
188
188
  requirements: []
189
189
  rubyforge_project:
190
- rubygems_version: 2.0.2
190
+ rubygems_version: 2.0.3
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: Cassandra ActiveModel