gotime-cassandra_object 4.10.1 → 4.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/Gemfile +1 -0
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/attribute_methods/typecasting.rb +2 -2
- data/lib/cassandra_object/persistence.rb +2 -5
- data/lib/cassandra_object/scope.rb +9 -1
- data/lib/cassandra_object/scoping.rb +9 -1
- data/lib/cassandra_object/types.rb +1 -0
- data/lib/cassandra_object/types/hash_type.rb +52 -0
- data/lib/cassandra_object/types/json_type.rb +0 -39
- data/lib/gotime-cassandra_object.rb +1 -0
- data/test/support/issue.rb +4 -0
- data/test/unit/attribute_methods_test.rb +7 -4
- data/test/unit/scope/query_methods_test.rb +6 -0
- data/test/unit/types/hash_type_test.rb +77 -0
- data/test/unit/types/json_type_test.rb +5 -59
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc64be77dc2226fed23bcf8c42c485481c9ce89c
|
4
|
+
data.tar.gz: 01fe5ae6645ce36caf4b5825b31ac985be16a55d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 115a5fb6f7a9286afcec5c80f6bca49c63c86ad6be6a879f4d06446d41bb8c66f251d6ad9400e7c3d5392ed5a2e6070e67450d690339d76e140468984b007516
|
7
|
+
data.tar.gz: 9cab61d72f194b8a66fb4251b107cc3862e07cf580d54c9d5094b71dbe54d041a2a32d8719cc2dc5b38222284c96ab787e9a2449cce4c54f79a46577e9346fbd
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -7,12 +7,12 @@ module CassandraObject
|
|
7
7
|
class_attribute :attribute_definitions
|
8
8
|
self.attribute_definitions = {}
|
9
9
|
|
10
|
-
%w(array boolean date float integer json string time).each do |type|
|
10
|
+
%w(array boolean date float hash_t integer json string time).each do |type|
|
11
11
|
instance_eval <<-EOV, __FILE__, __LINE__ + 1
|
12
12
|
def #{type}(*args)
|
13
13
|
options = args.extract_options!
|
14
14
|
args.each do |name|
|
15
|
-
attribute(name, options.merge(:type => :#{type}))
|
15
|
+
attribute(name, options.merge(:type => :#{type == 'hash_t' ? 'hash' : type}))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
EOV
|
@@ -9,11 +9,8 @@ module CassandraObject
|
|
9
9
|
module ClassMethods
|
10
10
|
def remove(id)
|
11
11
|
statement = "DELETE FROM #{column_family}#{write_option_string} WHERE "
|
12
|
-
|
13
|
-
|
14
|
-
else
|
15
|
-
statement += "KEY = ?"
|
16
|
-
end
|
12
|
+
statement += id.is_a?(Array) ? "KEY IN (?)" : "KEY = ?"
|
13
|
+
|
17
14
|
execute_batchable_cql statement, id
|
18
15
|
end
|
19
16
|
|
@@ -18,9 +18,17 @@ module CassandraObject
|
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
|
+
|
22
|
+
def scoping
|
23
|
+
previous, klass.current_scope = klass.current_scope, self
|
24
|
+
yield
|
25
|
+
ensure
|
26
|
+
klass.current_scope = previous
|
27
|
+
end
|
28
|
+
|
21
29
|
def method_missing(method_name, *args, &block)
|
22
30
|
if klass.respond_to?(method_name)
|
23
|
-
klass.send(method_name, *args, &block)
|
31
|
+
scoping { klass.send(method_name, *args, &block) }
|
24
32
|
elsif Array.method_defined?(method_name)
|
25
33
|
to_a.send(method_name, *args, &block)
|
26
34
|
else
|
@@ -12,7 +12,15 @@ module CassandraObject
|
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
def scope
|
15
|
-
Scope.new(self)
|
15
|
+
self.current_scope ||= Scope.new(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_scope
|
19
|
+
Thread.current["#{self}_current_scope"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def current_scope=(new_scope)
|
23
|
+
Thread.current["#{self}_current_scope"] = new_scope
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
@@ -2,6 +2,7 @@ CassandraObject::Type.register(:array, CassandraObject::Types::ArrayTyp
|
|
2
2
|
CassandraObject::Type.register(:boolean, CassandraObject::Types::BooleanType)
|
3
3
|
CassandraObject::Type.register(:date, CassandraObject::Types::DateType)
|
4
4
|
CassandraObject::Type.register(:float, CassandraObject::Types::FloatType)
|
5
|
+
CassandraObject::Type.register(:hash, CassandraObject::Types::HashType)
|
5
6
|
CassandraObject::Type.register(:integer, CassandraObject::Types::IntegerType)
|
6
7
|
CassandraObject::Type.register(:json, CassandraObject::Types::JsonType)
|
7
8
|
CassandraObject::Type.register(:time, CassandraObject::Types::TimeType)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module CassandraObject
|
2
|
+
module Types
|
3
|
+
class HashType < 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 { super }
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(obj)
|
21
|
+
modifying { super }
|
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
|
+
|
38
|
+
def encode(hash)
|
39
|
+
ActiveSupport::JSON.encode(hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
def decode(str)
|
43
|
+
ActiveSupport::JSON.decode(str)
|
44
|
+
end
|
45
|
+
|
46
|
+
def wrap(record, name, value)
|
47
|
+
DirtyHash.new(record, name, Hash(value), options)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,40 +1,6 @@
|
|
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
|
-
|
38
4
|
def encode(hash)
|
39
5
|
ActiveSupport::JSON.encode(hash)
|
40
6
|
end
|
@@ -42,11 +8,6 @@ module CassandraObject
|
|
42
8
|
def decode(str)
|
43
9
|
ActiveSupport::JSON.decode(str)
|
44
10
|
end
|
45
|
-
|
46
|
-
def wrap(record, name, value)
|
47
|
-
DirtyHash.new(record, name, Hash(value), options)
|
48
|
-
end
|
49
|
-
|
50
11
|
end
|
51
12
|
end
|
52
13
|
end
|
data/test/support/issue.rb
CHANGED
@@ -30,11 +30,14 @@ class CassandraObject::AttributeMethodsTest < CassandraObject::TestCase
|
|
30
30
|
assert_equal 'foo', issue.description
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
class ChildIssue < Issue
|
34
|
+
def title=(val)
|
35
|
+
self[:title] = val + ' lol'
|
36
|
+
end
|
37
|
+
end
|
35
38
|
|
36
|
-
test '
|
37
|
-
issue =
|
39
|
+
test 'override' do
|
40
|
+
issue = ChildIssue.new(title: 'hey')
|
38
41
|
|
39
42
|
assert_equal 'hey lol', issue.title
|
40
43
|
end
|
@@ -23,4 +23,10 @@ class CassandraObject::Scope::QueryMethodsTest < CassandraObject::TestCase
|
|
23
23
|
Issue.all
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
test "chaining where with scope" do
|
28
|
+
issue = Issue.create title: 'abc', description: 'def'
|
29
|
+
query = Issue.select(:title).for_key(issue.id)
|
30
|
+
assert_match /^SELECT KEY,title/, query.to_cql
|
31
|
+
end
|
26
32
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CassandraObject::Types::HashTypeTest < CassandraObject::Types::TestCase
|
4
|
+
test 'encode' do
|
5
|
+
assert_equal({a: 'b'}.to_json, coder.encode(a: 'b'))
|
6
|
+
assert_equal '-3', coder.encode(-3)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'decode' do
|
10
|
+
assert_equal({'a' => 'b'}, coder.decode({'a' => 'b'}.to_json))
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'setting marks dirty' do
|
14
|
+
record = temp_object do
|
15
|
+
string :name
|
16
|
+
hash_t :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
|
+
hash_t :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
|
+
hash_t :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
|
+
hash_t :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
|
+
|
77
|
+
end
|
@@ -10,67 +10,13 @@ class CassandraObject::Types::JsonTypeTest < CassandraObject::Types::TestCase
|
|
10
10
|
assert_equal({'a' => 'b'}, coder.decode({'a' => 'b'}.to_json))
|
11
11
|
end
|
12
12
|
|
13
|
-
test '
|
14
|
-
|
15
|
-
|
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
|
13
|
+
test 'encode array' do
|
14
|
+
assert_equal(['a', 'b'].to_json, coder.encode(['a', 'b']))
|
15
|
+
assert_equal '-3', coder.encode(-3)
|
61
16
|
end
|
62
17
|
|
63
|
-
test '
|
64
|
-
|
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
|
18
|
+
test 'decode array' do
|
19
|
+
assert_equal(['a', 'b'], coder.decode(['a', 'b'].to_json))
|
74
20
|
end
|
75
21
|
|
76
22
|
|
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.
|
4
|
+
version: 4.10.2
|
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-10-
|
12
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/cassandra_object/types/boolean_type.rb
|
123
123
|
- lib/cassandra_object/types/date_type.rb
|
124
124
|
- lib/cassandra_object/types/float_type.rb
|
125
|
+
- lib/cassandra_object/types/hash_type.rb
|
125
126
|
- lib/cassandra_object/types/integer_type.rb
|
126
127
|
- lib/cassandra_object/types/json_type.rb
|
127
128
|
- lib/cassandra_object/types/string_type.rb
|
@@ -163,6 +164,7 @@ files:
|
|
163
164
|
- test/unit/types/boolean_type_test.rb
|
164
165
|
- test/unit/types/date_type_test.rb
|
165
166
|
- test/unit/types/float_type_test.rb
|
167
|
+
- test/unit/types/hash_type_test.rb
|
166
168
|
- test/unit/types/integer_type_test.rb
|
167
169
|
- test/unit/types/json_type_test.rb
|
168
170
|
- test/unit/types/string_type_test.rb
|