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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7065981f0726fd662b2d6a42d8b2c8938e56b974
4
- data.tar.gz: cbd7d2ba31303203624b2bce28c5fc3b61737d38
3
+ metadata.gz: f263e66af88f25ad58871eacee736b9a13996b65
4
+ data.tar.gz: a223bf32c8be89d5173bc69bde176e52f512eb81
5
5
  SHA512:
6
- metadata.gz: 32474823df1bbb7ffe2b750896c88174b28310fe1f26212d848fabbb29a267215e41c2367cde0f0706fb748362730a1d806d3ae5d9cb76f227f9aebca1c28b62
7
- data.tar.gz: 735e41f64fc8e187f047ab3ceef93fb607a1db4b4e4fd1bccd0bd11e1b2c0db487a1b413f82bbf146a7be1dcc6e63a40c6eb05f3ddf543142c59f43aa43c431f
6
+ metadata.gz: 84e088745991bd331e55baca18e2f63318f0653766fa2c2466c8bfd9a402308d83dd02545c49a8f87f129e1bddb0a4b736acdd4fcf44df0eeb31329e1da9f64c
7
+ data.tar.gz: cf6b2c6b52aa2693a1b1d2013c4d5bd7cfd102dd67d1ad26002e2fe2b1b0d6ade18a4e397e003d8967d8cb605d6d1c131a37b97734e621ae8a41d2146294abc5
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '4.10.5'
5
+ s.version = '4.11.0'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
@@ -52,7 +52,11 @@ module CassandraObject
52
52
  end
53
53
 
54
54
  def attributes
55
- Hash[@attributes.map { |name, _| [name, read_attribute(name)] }]
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.to_sym]
84
+ !!attribute_definitions[name.to_s]
81
85
  end
82
86
 
83
87
  private
@@ -7,6 +7,10 @@ module CassandraObject
7
7
  @coder = coder.new(options)
8
8
  end
9
9
 
10
+ def default
11
+ coder.default
12
+ end
13
+
10
14
  def instantiate(record, value)
11
15
  value = value.nil? ? coder.default : value
12
16
  return if value.nil?
@@ -39,11 +39,11 @@ module CassandraObject
39
39
  raise "Must supply a :coder for #{name}"
40
40
  end
41
41
 
42
- attribute_definitions[name.to_sym] = AttributeMethods::Definition.new(name, coder, options)
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.to_sym]
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.to_sym].coder
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.each_key do |attr|
11
- unless attribute_exists?(attr)
12
- @attributes[attr.to_s] = self.class.typecast_attribute(self, attr, nil)
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", typecast_attributes(object, 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.to_s] = attribute_definitions[column_name.to_sym].coder.encode(value)
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 typecast_attributes(object, attributes)
95
- attributes = attributes.symbolize_keys
96
- Hash[attribute_definitions.map { |k, attribute_definition| [k.to_s, attribute_definition.instantiate(object, attributes[k])] }]
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.update(self.class.find(id).instance_variable_get('@attributes'))
163
+ @attributes = self.class.find(id).instance_variable_get('@attributes')
154
164
  self
155
165
  end
156
166
 
@@ -51,9 +51,9 @@ module CassandraObject
51
51
  end
52
52
  end
53
53
 
54
- def default
55
- []
56
- end
54
+ # def default
55
+ # []
56
+ # end
57
57
 
58
58
  def encode(array)
59
59
  raise ArgumentError.new("#{array.inspect} is not an Array") unless array.kind_of?(Array)
@@ -12,6 +12,10 @@ module CassandraObject
12
12
  def decode(str)
13
13
  Date.parse(str)
14
14
  end
15
+
16
+ def wrap(record, name, value)
17
+ value.to_date
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -11,6 +11,10 @@ module CassandraObject
11
11
  return nil if str.empty?
12
12
  str.to_i
13
13
  end
14
+
15
+ def wrap(record, name, value)
16
+ value.to_i
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -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[:custom_column]
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: nil})
19
+ klass.encode_attributes({'description' => nil})
20
20
  )
21
21
 
22
22
  assert_equal(
23
23
  {'description' => 'lol'},
24
- klass.encode_attributes({description: 'lol'})
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.10.5
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-13 00:00:00.000000000 Z
12
+ date: 2013-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel