sessionm-cassandra_object 2.2.10 → 2.2.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,6 +43,7 @@ module CassandraObject
43
43
  def id
44
44
  key.to_s
45
45
  end
46
+ alias :quoted_id :id
46
47
 
47
48
  def id=(key)
48
49
  self.key = self.class.parse_key(key)
@@ -2,18 +2,20 @@ module CassandraObject
2
2
  module Types
3
3
  module DecimalType
4
4
  def encode(value)
5
- raise ArgumentError.new("#{self} requires a BigDecimal") unless value.kind_of?(BigDecimal)
5
+ return nil if value.nil?
6
+ raise ArgumentError.new("#{self} requires a Numeric") unless value.kind_of?(Numeric)
6
7
  value.to_s
7
8
  end
8
9
  module_function :encode
9
10
 
10
- def decode(str, options={})
11
- return nil if str.empty?
12
- raise ArgumentError.new("Cannot convert #{str} into a BigDecimal") unless str.kind_of?(String)
11
+ def decode(value, options={})
12
+ return nil if value.nil?
13
+ value = value.to_s if value.kind_of?(Numeric)
14
+ raise ArgumentError.new("Cannot convert #{value} into a BigDecimal") unless value.kind_of?(String)
13
15
  if options[:precision].present?
14
- BigDecimal.new(str, options[:precision])
16
+ BigDecimal.new(value, options[:precision])
15
17
  else
16
- BigDecimal.new(str)
18
+ BigDecimal.new(value)
17
19
  end
18
20
  end
19
21
  module_function :decode
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '2.2.10'
5
+ s.version = '2.2.12'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -2,10 +2,15 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class CassandraObject::Types::DecimalTypeTest < CassandraObject::TestCase
4
4
  test 'encode' do
5
+ assert_equal nil, CassandraObject::Types::DecimalType.encode(nil)
6
+ assert_equal '3', CassandraObject::Types::DecimalType.encode(3)
7
+ assert_equal '3.14', CassandraObject::Types::DecimalType.encode(3.14)
5
8
  assert_equal '3.14', CassandraObject::Types::DecimalType.encode(BigDecimal.new('3.14'))
6
9
  end
7
10
 
8
11
  test 'decode' do
12
+ assert_equal nil, CassandraObject::Types::DecimalType.decode(nil)
13
+ assert_equal BigDecimal.new('0.001'), CassandraObject::Types::DecimalType.decode(0.001)
9
14
  assert_equal BigDecimal.new('0.001'), CassandraObject::Types::DecimalType.decode('.001')
10
15
  assert_equal [9, 18], CassandraObject::Types::DecimalType.decode('.001').precs
11
16
  assert_equal [9, 27], CassandraObject::Types::DecimalType.decode('.001', :precision => 14).precs
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.10
4
+ version: 2.2.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ date: 2011-08-03 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
- requirement: &70293952989880 !ruby/object:Gem::Requirement
18
+ requirement: &70325359150480 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '3.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70293952989880
26
+ version_requirements: *70325359150480
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cassandra
29
- requirement: &70293952989420 !ruby/object:Gem::Requirement
29
+ requirement: &70325359149920 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 0.11.3
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70293952989420
37
+ version_requirements: *70325359149920
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: bundler
40
- requirement: &70293952988960 !ruby/object:Gem::Requirement
40
+ requirement: &70325359149440 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: 1.0.0
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70293952988960
48
+ version_requirements: *70325359149440
49
49
  description: Cassandra ActiveModel
50
50
  email: klange@sessionm.com
51
51
  executables: []