gotime-cassandra_object 4.11.0 → 4.11.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 +4 -4
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/types/array_type.rb +3 -59
- data/test/unit/types/array_type_test.rb +2 -52
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3f176532fdfd5a0c54cc37fae1669de28f3871
|
4
|
+
data.tar.gz: 263463406d38663bf097c49810273859982362e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc7bf9e4be31c169b13caf13cf4c0d458354e6cf3e989250749de3da7aefe61f9868b041fe5c3c269439c662e17896d4b6943ebbcdc37066e86f2ea223385be5
|
7
|
+
data.tar.gz: 2519496ba7ddad57c635f06b361f3068cb50fd19a7ae5b7a9d7c2462724478a2692fca8ec79f3a95dc737dda5b25b6d3e46d204fa2e6fdc6da7ea96a1215cbbc
|
@@ -1,75 +1,19 @@
|
|
1
1
|
module CassandraObject
|
2
2
|
module Types
|
3
3
|
class ArrayType < BaseType
|
4
|
-
class DirtyArray < Array
|
5
|
-
attr_accessor :record, :name, :options
|
6
|
-
def initialize(record, name, array, options)
|
7
|
-
@record = record
|
8
|
-
@name = name.to_s
|
9
|
-
@options = options
|
10
|
-
|
11
|
-
super(array)
|
12
|
-
setify!
|
13
|
-
end
|
14
|
-
|
15
|
-
def <<(obj)
|
16
|
-
modifying do
|
17
|
-
super
|
18
|
-
setify!
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def delete(obj)
|
23
|
-
modifying do
|
24
|
-
super
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
def setify!
|
30
|
-
if options[:unique]
|
31
|
-
reject!(&:blank?)
|
32
|
-
uniq!
|
33
|
-
begin sort! rescue ArgumentError end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def modifying
|
38
|
-
unless record.changed_attributes.include?(name)
|
39
|
-
original = dup
|
40
|
-
end
|
41
|
-
|
42
|
-
result = yield
|
43
|
-
|
44
|
-
if !record.changed_attributes.key?(name) && original != self
|
45
|
-
record.changed_attributes[name] = original
|
46
|
-
end
|
47
|
-
|
48
|
-
record.send("#{name}=", self)
|
49
|
-
|
50
|
-
result
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# def default
|
55
|
-
# []
|
56
|
-
# end
|
57
|
-
|
58
4
|
def encode(array)
|
59
5
|
raise ArgumentError.new("#{array.inspect} is not an Array") unless array.kind_of?(Array)
|
60
6
|
array.to_a.to_json
|
61
7
|
end
|
62
8
|
|
63
9
|
def decode(str)
|
64
|
-
return
|
10
|
+
return nil if str.blank?
|
65
11
|
|
66
|
-
ActiveSupport::JSON.decode(str)
|
67
|
-
array.uniq! if options[:unique]
|
68
|
-
end
|
12
|
+
ActiveSupport::JSON.decode(str)
|
69
13
|
end
|
70
14
|
|
71
15
|
def wrap(record, name, value)
|
72
|
-
|
16
|
+
value
|
73
17
|
end
|
74
18
|
end
|
75
19
|
end
|
@@ -11,57 +11,7 @@ class CassandraObject::Types::ArrayTypeTest < CassandraObject::Types::TestCase
|
|
11
11
|
|
12
12
|
test 'decode' do
|
13
13
|
assert_equal ['1', '2'], coder.decode(['1', '2'].to_json)
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
16
|
-
end
|
17
|
-
|
18
|
-
class TestIssue < CassandraObject::Base
|
19
|
-
self.column_family = 'Issues'
|
20
|
-
array :favorite_colors, unique: true
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'append marks dirty' do
|
24
|
-
issue = TestIssue.create favorite_colors: []
|
25
|
-
assert !issue.changed?
|
26
|
-
|
27
|
-
issue.favorite_colors << 'red'
|
28
|
-
assert issue.changed?
|
29
|
-
assert_equal({'favorite_colors' => [[], ['red']]}, issue.changes)
|
30
|
-
end
|
31
|
-
|
32
|
-
test 'delete marks dirty' do
|
33
|
-
issue = TestIssue.create favorite_colors: ['red']
|
34
|
-
assert !issue.changed?
|
35
|
-
|
36
|
-
issue.favorite_colors.delete('red')
|
37
|
-
assert issue.changed?
|
38
|
-
assert_equal({'favorite_colors' => [['red'], []]}, issue.changes)
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'unique array removes blank' do
|
42
|
-
issue = TestIssue.create favorite_colors: ['blue', 'red', '', nil]
|
43
|
-
assert_equal ['blue', 'red'], issue.favorite_colors
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'unique array uniquifies' do
|
47
|
-
issue = TestIssue.create favorite_colors: ['blue', 'red']
|
48
|
-
|
49
|
-
issue.favorite_colors = ['red', 'red', 'blue']
|
50
|
-
assert !issue.changed?
|
51
|
-
|
52
|
-
issue.favorite_colors = ['red', 'green']
|
53
|
-
assert issue.changed?
|
54
|
-
end
|
55
|
-
|
56
|
-
test 'unique array rescues argument error' do
|
57
|
-
issue = TestIssue.create favorite_colors: [1, 'red']
|
58
|
-
|
59
|
-
assert_equal [1, 'red'], issue.favorite_colors
|
60
|
-
end
|
61
|
-
|
62
|
-
test 'write non array' do
|
63
|
-
issue = TestIssue.create favorite_colors: true
|
64
|
-
|
65
|
-
assert_equal [true], issue.favorite_colors
|
14
|
+
assert_equal nil, coder.decode(nil)
|
15
|
+
assert_equal nil, coder.decode('')
|
66
16
|
end
|
67
17
|
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.11.
|
4
|
+
version: 4.11.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-11-
|
12
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|