gotime-cassandra_object 2.8.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '2.8.0'
5
+ s.version = '2.8.1'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -9,7 +9,7 @@ module CassandraObject
9
9
 
10
10
  attribute_method_suffix("", "=")
11
11
 
12
- %w(array boolean date float integer time time_with_zone string).each do |type|
12
+ %w(array boolean date float integer json string time time_with_zone).each do |type|
13
13
  instance_eval <<-EOV, __FILE__, __LINE__ + 1
14
14
  def #{type}(name, options = {}) # def string(name, options = {})
15
15
  attribute(name, options.update(type: :#{type})) # attribute(name, options.update(type: :string))
@@ -41,10 +41,6 @@ module CassandraObject
41
41
  attribute_definitions[name.to_sym] = AttributeMethods::Definition.new(name, coder, options)
42
42
  end
43
43
 
44
- def json(name, options = {})
45
- attribute(name, options.update(type: :hash))
46
- end
47
-
48
44
  def instantiate_attribute(record, name, value)
49
45
  if attribute_definition = attribute_definitions[name.to_sym]
50
46
  attribute_definition.instantiate(record, value)
@@ -56,7 +56,7 @@ module CassandraObject
56
56
  self.attributes = attributes
57
57
  attribute_definitions.each do |attr, attribute_definition|
58
58
  unless attribute_exists?(attr)
59
- write_attribute(attr, attribute_definition.instantiate(self, nil))
59
+ self.attributes[attr] = self.class.instantiate_attribute(self, attr, nil)
60
60
  end
61
61
  end
62
62
 
@@ -2,8 +2,8 @@ CassandraObject::Type.register(:array, CassandraObject::Types::ArrayTyp
2
2
  CassandraObject::Type.register(:boolean, CassandraObject::Types::BooleanType)
3
3
  CassandraObject::Type.register(:date, CassandraObject::Types::DateType)
4
4
  CassandraObject::Type.register(:float, CassandraObject::Types::FloatType)
5
- CassandraObject::Type.register(:hash, CassandraObject::Types::HashType)
6
5
  CassandraObject::Type.register(:integer, CassandraObject::Types::IntegerType)
6
+ CassandraObject::Type.register(:json, CassandraObject::Types::JsonType)
7
7
  CassandraObject::Type.register(:time, CassandraObject::Types::TimeType)
8
8
  CassandraObject::Type.register(:time_with_zone, CassandraObject::Types::TimeWithZoneType)
9
9
  CassandraObject::Type.register(:string, CassandraObject::Types::StringType)
@@ -1,8 +1,7 @@
1
1
  module CassandraObject
2
2
  module Types
3
- class HashType < BaseType
3
+ class JsonType < BaseType
4
4
  def encode(hash)
5
- raise ArgumentError.new("#{self} requires a Hash") unless hash.kind_of?(Hash)
6
5
  ActiveSupport::JSON.encode(hash)
7
6
  end
8
7
 
@@ -47,8 +47,8 @@ module CassandraObject
47
47
  autoload :BooleanType
48
48
  autoload :DateType
49
49
  autoload :FloatType
50
- autoload :HashType
51
50
  autoload :IntegerType
51
+ autoload :JsonType
52
52
  autoload :StringType
53
53
  autoload :TimeType
54
54
  autoload :TimeWithZoneType
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ class CassandraObject::Types::JsonTypeTest < CassandraObject::Types::TestCase
4
+ test 'encode' do
5
+ assert_equal({a: 'b'}.to_json, coder.encode(a: 'b'))
6
+ assert_equal '-3', coder.encode(-3)
7
+ end
8
+
9
+ test 'decode' do
10
+ assert_equal({'a' => 'b'}, coder.decode({'a' => 'b'}.to_json))
11
+ end
12
+ 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: 2.8.0
4
+ version: 2.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-21 00:00:00.000000000Z
13
+ date: 2011-11-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &70327481619240 !ruby/object:Gem::Requirement
17
+ requirement: &70248930981540 !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: *70327481619240
25
+ version_requirements: *70248930981540
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cassandra
28
- requirement: &70327481618340 !ruby/object:Gem::Requirement
28
+ requirement: &70248930981000 !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: *70327481618340
36
+ version_requirements: *70248930981000
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &70327481617260 !ruby/object:Gem::Requirement
39
+ requirement: &70248930980520 !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: *70327481617260
47
+ version_requirements: *70248930980520
48
48
  description: Cassandra ActiveModel
49
49
  email: gems@gotime.com
50
50
  executables: []
@@ -105,8 +105,8 @@ files:
105
105
  - lib/cassandra_object/types/boolean_type.rb
106
106
  - lib/cassandra_object/types/date_type.rb
107
107
  - lib/cassandra_object/types/float_type.rb
108
- - lib/cassandra_object/types/hash_type.rb
109
108
  - lib/cassandra_object/types/integer_type.rb
109
+ - lib/cassandra_object/types/json_type.rb
110
110
  - lib/cassandra_object/types/string_type.rb
111
111
  - lib/cassandra_object/types/time_type.rb
112
112
  - lib/cassandra_object/types/time_with_zone_type.rb
@@ -132,8 +132,8 @@ files:
132
132
  - test/types/boolean_type_test.rb
133
133
  - test/types/date_type_test.rb
134
134
  - test/types/float_type_test.rb
135
- - test/types/hash_type_test.rb
136
135
  - test/types/integer_type_test.rb
136
+ - test/types/json_type_test.rb
137
137
  - test/types/string_type_test.rb
138
138
  - test/types/time_type_test.rb
139
139
  - test/types/time_with_zone_type_test.rb
@@ -1,4 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CassandraObject::Type::BooleanTypeTest < CassandraObject::Types::TestCase
4
- end