gotime-cassandra_object 2.11.7 → 2.11.8
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.
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/attribute_methods/typecasting.rb +4 -0
- data/lib/cassandra_object/base.rb +0 -2
- data/lib/cassandra_object/migrations.rb +0 -11
- data/lib/cassandra_object/persistence.rb +5 -6
- data/lib/cassandra_object/types/array_type.rb +1 -1
- data/lib/cassandra_object/types/boolean_type.rb +1 -1
- data/lib/cassandra_object/types/date_type.rb +1 -1
- data/lib/cassandra_object/types/float_type.rb +1 -1
- data/lib/cassandra_object/types/integer_type.rb +1 -1
- data/lib/cassandra_object/types/string_type.rb +1 -1
- data/lib/cassandra_object/types/time_type.rb +1 -1
- data/test/unit/persistence_test.rb +6 -6
- metadata +2 -2
@@ -6,9 +6,6 @@ module CassandraObject
|
|
6
6
|
included do
|
7
7
|
class_attribute :migrations
|
8
8
|
self.migrations = []
|
9
|
-
|
10
|
-
class_attribute :current_schema_version
|
11
|
-
self.current_schema_version = 0
|
12
9
|
end
|
13
10
|
|
14
11
|
autoload :Migration
|
@@ -19,17 +16,9 @@ module CassandraObject
|
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
22
|
-
def schema_version
|
23
|
-
Integer(@schema_version || self.class.current_schema_version)
|
24
|
-
end
|
25
|
-
|
26
19
|
module ClassMethods
|
27
20
|
def migrate(version, &blk)
|
28
21
|
migrations << Migration.new(version, blk)
|
29
|
-
|
30
|
-
if version > self.current_schema_version
|
31
|
-
self.current_schema_version = version
|
32
|
-
end
|
33
22
|
end
|
34
23
|
end
|
35
24
|
end
|
@@ -21,8 +21,8 @@ module CassandraObject
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def write(key, attributes
|
25
|
-
attributes = encode_attributes(attributes
|
24
|
+
def write(key, attributes)
|
25
|
+
attributes = encode_attributes(attributes)
|
26
26
|
ActiveSupport::Notifications.instrument("insert.cassandra_object", column_family: column_family, key: key, attributes: attributes) do
|
27
27
|
connection.insert(column_family, key.to_s, attributes, consistency: thrift_write_consistency)
|
28
28
|
# if nil_attributes.any?
|
@@ -33,7 +33,6 @@ module CassandraObject
|
|
33
33
|
|
34
34
|
def instantiate(key, attributes)
|
35
35
|
allocate.tap do |object|
|
36
|
-
object.instance_variable_set("@schema_version", attributes.delete('schema_version'))
|
37
36
|
object.instance_variable_set("@key", parse_key(key)) if key
|
38
37
|
object.instance_variable_set("@new_record", false)
|
39
38
|
object.instance_variable_set("@destroyed", false)
|
@@ -41,8 +40,8 @@ module CassandraObject
|
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
|
-
def encode_attributes(attributes
|
45
|
-
encoded = {
|
43
|
+
def encode_attributes(attributes)
|
44
|
+
encoded = {}
|
46
45
|
attributes.each do |column_name, value|
|
47
46
|
# The ruby thrift gem expects all strings to be encoded as ascii-8bit.
|
48
47
|
unless value.nil?
|
@@ -126,7 +125,7 @@ module CassandraObject
|
|
126
125
|
|
127
126
|
def write
|
128
127
|
changed_attributes = changed.inject({}) { |h, n| h[n] = read_attribute(n); h }
|
129
|
-
self.class.write(key, changed_attributes
|
128
|
+
self.class.write(key, changed_attributes)
|
130
129
|
end
|
131
130
|
end
|
132
131
|
end
|
@@ -56,7 +56,7 @@ module CassandraObject
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def encode(array)
|
59
|
-
raise ArgumentError.new("#{
|
59
|
+
raise ArgumentError.new("#{array.inspect} is not an Array") unless array.kind_of?(Array)
|
60
60
|
array.to_a.to_json
|
61
61
|
end
|
62
62
|
|
@@ -5,7 +5,7 @@ module CassandraObject
|
|
5
5
|
REGEX = /\A\d{4}-\d{2}-\d{2}\Z/
|
6
6
|
|
7
7
|
def encode(value)
|
8
|
-
raise ArgumentError.new("#{
|
8
|
+
raise ArgumentError.new("#{value.inspect} is not a Date") unless value.kind_of?(Date)
|
9
9
|
value.strftime(FORMAT)
|
10
10
|
end
|
11
11
|
|
@@ -3,7 +3,7 @@ module CassandraObject
|
|
3
3
|
class FloatType < BaseType
|
4
4
|
REGEX = /\A[-+]?\d+(\.\d+)?\Z/
|
5
5
|
def encode(float)
|
6
|
-
raise ArgumentError.new("#{
|
6
|
+
raise ArgumentError.new("#{float.inspect} is not a Float") unless float.kind_of?(Float)
|
7
7
|
float.to_s
|
8
8
|
end
|
9
9
|
|
@@ -3,7 +3,7 @@ module CassandraObject
|
|
3
3
|
class IntegerType < BaseType
|
4
4
|
REGEX = /\A[-+]?\d+\Z/
|
5
5
|
def encode(int)
|
6
|
-
raise ArgumentError.new("#{
|
6
|
+
raise ArgumentError.new("#{int.inspect} is not an Integer.") unless int.kind_of?(Integer)
|
7
7
|
int.to_s
|
8
8
|
end
|
9
9
|
|
@@ -2,7 +2,7 @@ module CassandraObject
|
|
2
2
|
module Types
|
3
3
|
class StringType < BaseType
|
4
4
|
def encode(str)
|
5
|
-
raise ArgumentError.new("#{
|
5
|
+
raise ArgumentError.new("#{str.inspect} is not a String") unless str.kind_of?(String)
|
6
6
|
str.dup
|
7
7
|
end
|
8
8
|
|
@@ -10,7 +10,7 @@ module CassandraObject
|
|
10
10
|
\s*\z/ix
|
11
11
|
|
12
12
|
def encode(time)
|
13
|
-
raise ArgumentError.new("#{
|
13
|
+
raise ArgumentError.new("#{time.inspect} is not a Time") unless time.kind_of?(Time)
|
14
14
|
time.utc.xmlschema(6)
|
15
15
|
end
|
16
16
|
|
@@ -7,18 +7,18 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
assert_equal(
|
10
|
-
{
|
11
|
-
klass.encode_attributes({}
|
10
|
+
{},
|
11
|
+
klass.encode_attributes({})
|
12
12
|
)
|
13
13
|
|
14
14
|
assert_equal(
|
15
|
-
{
|
16
|
-
klass.encode_attributes({description: nil}
|
15
|
+
{},
|
16
|
+
klass.encode_attributes({description: nil})
|
17
17
|
)
|
18
18
|
|
19
19
|
assert_equal(
|
20
|
-
{'description' => 'lol'
|
21
|
-
klass.encode_attributes({description: 'lol'}
|
20
|
+
{'description' => 'lol'},
|
21
|
+
klass.encode_attributes({description: 'lol'})
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
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: 2.11.
|
4
|
+
version: 2.11.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-05-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|