gotime-cassandra_object 2.6.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -59,6 +59,10 @@ module CassandraObject
|
|
59
59
|
model_attributes[name] = Attribute.new(name, type_mapping, options)
|
60
60
|
end
|
61
61
|
|
62
|
+
def json(name)
|
63
|
+
attribute(name, type: :hash)
|
64
|
+
end
|
65
|
+
|
62
66
|
def instantiate_attribute(record, name, value)
|
63
67
|
if model_attribute = model_attributes[name]
|
64
68
|
model_attribute.instantiate(record, value)
|
@@ -31,36 +31,6 @@ module CassandraObject
|
|
31
31
|
self.current_schema_version = version
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
|
-
def instantiate(key, attributes)
|
36
|
-
version = attributes.delete('schema_version')
|
37
|
-
original_attributes = attributes.dup
|
38
|
-
if version == current_schema_version
|
39
|
-
return super(key, attributes)
|
40
|
-
end
|
41
|
-
|
42
|
-
versions_to_migrate = ((version.to_i + 1)..current_schema_version)
|
43
|
-
|
44
|
-
migrations_to_run = versions_to_migrate.map do |v|
|
45
|
-
migrations.find {|m| m.version == v}
|
46
|
-
end
|
47
|
-
|
48
|
-
if migrations_to_run.any?(&:nil?)
|
49
|
-
raise MigrationNotFoundError.new(version, migrations)
|
50
|
-
end
|
51
|
-
|
52
|
-
migrations_to_run.inject(attributes) do |attrs, migration|
|
53
|
-
migration.run(attrs)
|
54
|
-
@schema_version = migration.version.to_s
|
55
|
-
attrs
|
56
|
-
end
|
57
|
-
|
58
|
-
super(key, attributes).tap do |record|
|
59
|
-
original_attributes.diff(attributes).keys.each do |attribute|
|
60
|
-
record.send :attribute_will_change!, attribute
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
34
|
end
|
65
35
|
end
|
66
36
|
end
|
@@ -32,7 +32,7 @@ module CassandraObject
|
|
32
32
|
|
33
33
|
def instantiate(key, attributes)
|
34
34
|
# remove any attributes we don't know about. we would do this earlier, but we want to make such
|
35
|
-
#
|
35
|
+
# attributes available to migrations
|
36
36
|
attributes.delete_if { |k,_| model_attributes[k].nil? }
|
37
37
|
|
38
38
|
allocate.tap do |object|
|
@@ -57,10 +57,6 @@ module CassandraObject
|
|
57
57
|
def decode_columns_hash(object, attributes)
|
58
58
|
Hash[attributes.map { |k, v| [k.to_s, instantiate_attribute(object, k, v)] }]
|
59
59
|
end
|
60
|
-
|
61
|
-
def column_family_configuration
|
62
|
-
[{:Name => column_family, :CompareWith => "UTF8Type"}]
|
63
|
-
end
|
64
60
|
end
|
65
61
|
|
66
62
|
def new_record?
|
data/test/attributes_test.rb
CHANGED
@@ -8,9 +8,12 @@ class CassandraObject::AttributesTest < CassandraObject::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class TestIssue < CassandraObject::Base
|
11
|
-
|
11
|
+
key :uuid
|
12
|
+
self.column_family = 'Issues'
|
13
|
+
|
12
14
|
attribute :custom_column, type: CustomType, coder: CustomCoder
|
13
15
|
integer :price
|
16
|
+
json :orders
|
14
17
|
end
|
15
18
|
|
16
19
|
class TestChildIssue < TestIssue
|
@@ -24,6 +27,14 @@ class CassandraObject::AttributesTest < CassandraObject::TestCase
|
|
24
27
|
assert_equal CustomType, model_attribute.expected_type
|
25
28
|
end
|
26
29
|
|
30
|
+
test 'json attribute' do
|
31
|
+
issue = TestIssue.create! orders: {'a' => 'b'}
|
32
|
+
|
33
|
+
issue = TestIssue.find issue.id
|
34
|
+
|
35
|
+
assert_equal({'a' => 'b'}, issue.orders)
|
36
|
+
end
|
37
|
+
|
27
38
|
test 'instantiate_attribute' do
|
28
39
|
assert_equal 1, TestIssue.instantiate_attribute(TestIssue.new, 'price', 1)
|
29
40
|
assert_equal 1, TestIssue.instantiate_attribute(TestIssue.new, :price, 1)
|
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.6.
|
4
|
+
version: 2.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2011-08-29 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &70147973264920 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70147973264920
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cassandra
|
28
|
-
requirement: &
|
28
|
+
requirement: &70147973264260 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.12.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70147973264260
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70147973263640 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70147973263640
|
48
48
|
description: Cassandra ActiveModel
|
49
49
|
email: gems@gotime.com
|
50
50
|
executables: []
|