gotime-cassandra_object 4.10.5 → 4.11.0
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/attribute_methods.rb +6 -2
- data/lib/cassandra_object/attribute_methods/definition.rb +4 -0
- data/lib/cassandra_object/attribute_methods/typecasting.rb +3 -3
- data/lib/cassandra_object/core.rb +3 -3
- data/lib/cassandra_object/persistence.rb +16 -6
- data/lib/cassandra_object/types/array_type.rb +3 -3
- data/lib/cassandra_object/types/date_type.rb +4 -0
- data/lib/cassandra_object/types/integer_type.rb +4 -0
- data/test/unit/attribute_methods/typecasting_test.rb +1 -1
- data/test/unit/persistence_test.rb +2 -2
- data/test/unit/types/array_type_test.rb +0 -4
- 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: f263e66af88f25ad58871eacee736b9a13996b65
|
4
|
+
data.tar.gz: a223bf32c8be89d5173bc69bde176e52f512eb81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84e088745991bd331e55baca18e2f63318f0653766fa2c2466c8bfd9a402308d83dd02545c49a8f87f129e1bddb0a4b736acdd4fcf44df0eeb31329e1da9f64c
|
7
|
+
data.tar.gz: cf6b2c6b52aa2693a1b1d2013c4d5bd7cfd102dd67d1ad26002e2fe2b1b0d6ade18a4e397e003d8967d8cb605d6d1c131a37b97734e621ae8a41d2146294abc5
|
@@ -52,7 +52,11 @@ module CassandraObject
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def attributes
|
55
|
-
|
55
|
+
results = {}
|
56
|
+
@attributes.each_key do |key|
|
57
|
+
results[key] = read_attribute(key)
|
58
|
+
end
|
59
|
+
results
|
56
60
|
end
|
57
61
|
|
58
62
|
def attributes=(attributes)
|
@@ -77,7 +81,7 @@ module CassandraObject
|
|
77
81
|
|
78
82
|
protected
|
79
83
|
def attribute_method?(name)
|
80
|
-
!!attribute_definitions[name.
|
84
|
+
!!attribute_definitions[name.to_s]
|
81
85
|
end
|
82
86
|
|
83
87
|
private
|
@@ -39,11 +39,11 @@ module CassandraObject
|
|
39
39
|
raise "Must supply a :coder for #{name}"
|
40
40
|
end
|
41
41
|
|
42
|
-
attribute_definitions[name.
|
42
|
+
attribute_definitions[name.to_s] = AttributeMethods::Definition.new(name, coder, options)
|
43
43
|
end
|
44
44
|
|
45
45
|
def typecast_attribute(record, name, value)
|
46
|
-
if attribute_definition = attribute_definitions[name.
|
46
|
+
if attribute_definition = attribute_definitions[name.to_s]
|
47
47
|
attribute_definition.instantiate(record, value)
|
48
48
|
else
|
49
49
|
raise NoMethodError, "Unknown attribute #{name.inspect}"
|
@@ -51,7 +51,7 @@ module CassandraObject
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def coder_for(attribute)
|
54
|
-
attribute_definitions[attribute.
|
54
|
+
attribute_definitions[attribute.to_s].coder
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -7,9 +7,9 @@ module CassandraObject
|
|
7
7
|
@destroyed = false
|
8
8
|
@attributes = {}
|
9
9
|
self.attributes = attributes || {}
|
10
|
-
attribute_definitions.
|
11
|
-
unless attribute_exists?(
|
12
|
-
@attributes[
|
10
|
+
attribute_definitions.each_value do |definition|
|
11
|
+
unless definition.default.nil? || attribute_exists?(definition.name)
|
12
|
+
@attributes[definition.name] = definition.default
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -53,7 +53,7 @@ module CassandraObject
|
|
53
53
|
object.instance_variable_set("@id", id) if id
|
54
54
|
object.instance_variable_set("@new_record", false)
|
55
55
|
object.instance_variable_set("@destroyed", false)
|
56
|
-
object.instance_variable_set("@attributes",
|
56
|
+
object.instance_variable_set("@attributes", typecast_persisted_attributes(object, attributes))
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -61,7 +61,7 @@ module CassandraObject
|
|
61
61
|
encoded = {}
|
62
62
|
attributes.each do |column_name, value|
|
63
63
|
unless value.nil?
|
64
|
-
encoded[column_name
|
64
|
+
encoded[column_name] = attribute_definitions[column_name].coder.encode(value)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
encoded
|
@@ -91,9 +91,19 @@ module CassandraObject
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
def
|
95
|
-
attributes
|
96
|
-
|
94
|
+
def typecast_persisted_attributes(object, attributes)
|
95
|
+
attributes.each do |key, value|
|
96
|
+
next unless definition = attribute_definitions[key]
|
97
|
+
attributes[key] = definition.instantiate(object, value)
|
98
|
+
end
|
99
|
+
|
100
|
+
attribute_definitions.each_value do |definition|
|
101
|
+
unless definition.default.nil? || attributes.has_key?(definition.name)
|
102
|
+
attributes[definition.name] = definition.default
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
attributes
|
97
107
|
end
|
98
108
|
|
99
109
|
def write_option_string(ignore_batching = false)
|
@@ -150,7 +160,7 @@ module CassandraObject
|
|
150
160
|
|
151
161
|
def reload
|
152
162
|
clear_belongs_to_cache
|
153
|
-
@attributes
|
163
|
+
@attributes = self.class.find(id).instance_variable_get('@attributes')
|
154
164
|
self
|
155
165
|
end
|
156
166
|
|
@@ -29,7 +29,7 @@ class CassandraObject::AttributeMethods::TypecastingTest < CassandraObject::Test
|
|
29
29
|
end
|
30
30
|
|
31
31
|
test 'custom attribute definer' do
|
32
|
-
model_attribute = TestIssue.attribute_definitions[
|
32
|
+
model_attribute = TestIssue.attribute_definitions['custom_column']
|
33
33
|
|
34
34
|
assert_kind_of CustomCoder, model_attribute.coder
|
35
35
|
assert_equal 'custom_column', model_attribute.name
|
@@ -16,12 +16,12 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
|
|
16
16
|
|
17
17
|
assert_equal(
|
18
18
|
{},
|
19
|
-
klass.encode_attributes({description
|
19
|
+
klass.encode_attributes({'description' => nil})
|
20
20
|
)
|
21
21
|
|
22
22
|
assert_equal(
|
23
23
|
{'description' => 'lol'},
|
24
|
-
klass.encode_attributes({description
|
24
|
+
klass.encode_attributes({'description' => 'lol'})
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
@@ -20,10 +20,6 @@ class CassandraObject::Types::ArrayTypeTest < CassandraObject::Types::TestCase
|
|
20
20
|
array :favorite_colors, unique: true
|
21
21
|
end
|
22
22
|
|
23
|
-
test 'default' do
|
24
|
-
assert_equal [], TestIssue.new.favorite_colors
|
25
|
-
end
|
26
|
-
|
27
23
|
test 'append marks dirty' do
|
28
24
|
issue = TestIssue.create favorite_colors: []
|
29
25
|
assert !issue.changed?
|
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.
|
4
|
+
version: 4.11.0
|
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-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|