sessionm-cassandra_object 2.2.6 → 2.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ module CassandraObject
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- class_attribute :connection_spec
6
+ class_attribute :connection
7
7
  end
8
8
 
9
9
  module ClassMethods
@@ -13,16 +13,7 @@ module CassandraObject
13
13
  }
14
14
  def establish_connection(spec)
15
15
  spec.reverse_merge!(DEFAULT_OPTIONS)
16
- @connection = Cassandra.new(spec[:keyspace], spec[:servers], spec[:thrift].symbolize_keys!)
17
- end
18
-
19
- def connection=(val)
20
- @connection = val
21
- end
22
-
23
- def connection
24
- establish_connection(connection_spec) if @connection.nil?
25
- @connection
16
+ self.connection = Cassandra.new(spec[:keyspace], spec[:servers], spec[:thrift].symbolize_keys!)
26
17
  end
27
18
  end
28
19
  end
@@ -0,0 +1,18 @@
1
+ module CassandraObject
2
+ module Types
3
+ module DecimalType
4
+ def encode(value)
5
+ raise ArgumentError.new("#{self} requires a BigDecimal") unless value.kind_of?(BigDecimal)
6
+ value.to_s
7
+ end
8
+ module_function :encode
9
+
10
+ def decode(str)
11
+ return nil if str.empty?
12
+ raise ArgumentError.new("Cannot convert #{str} into a BigDecimal") unless str.kind_of?(String)
13
+ BigDecimal.new(str)
14
+ end
15
+ module_function :decode
16
+ end
17
+ end
18
+ end
@@ -2,6 +2,7 @@ CassandraObject::Type.register(:array, Array, CassandraObject::Types::ArrayType)
2
2
  CassandraObject::Type.register(:boolean, Object, CassandraObject::Types::BooleanType)
3
3
  CassandraObject::Type.register(:date, Date, CassandraObject::Types::DateType)
4
4
  CassandraObject::Type.register(:float, Float, CassandraObject::Types::FloatType)
5
+ CassandraObject::Type.register(:decimal, BigDecimal, CassandraObject::Types::DecimalType)
5
6
  CassandraObject::Type.register(:hash, Hash, CassandraObject::Types::HashType)
6
7
  CassandraObject::Type.register(:integer, Integer, CassandraObject::Types::IntegerType)
7
8
  CassandraObject::Type.register(:set, Array, CassandraObject::Types::SetType)
@@ -36,6 +36,7 @@ module CassandraObject
36
36
  autoload :ArrayType
37
37
  autoload :BooleanType
38
38
  autoload :DateType
39
+ autoload :DecimalType
39
40
  autoload :FloatType
40
41
  autoload :HashType
41
42
  autoload :IntegerType
@@ -46,4 +47,4 @@ module CassandraObject
46
47
  end
47
48
  end
48
49
 
49
- require 'cassandra_object/railtie'
50
+ require 'cassandra_object/railtie'
@@ -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.6'
5
+ s.version = '2.2.8'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
data/test/test_helper.rb CHANGED
@@ -7,16 +7,16 @@ require 'rails/test_help'
7
7
 
8
8
  class Issue < CassandraObject::Base
9
9
  key :uuid
10
- attribute :description, type: :string
10
+ attribute :description, :type => :string
11
11
  end
12
12
 
13
13
  module CassandraObject
14
14
  class TestCase < ActiveSupport::TestCase
15
15
  setup do
16
16
  CassandraObject::Base.establish_connection(
17
- keyspace: 'place_directory_development',
17
+ :keyspace => 'place_directory_development',
18
18
  # servers: '192.168.0.100:9160'
19
- servers: '127.0.0.1:9160'
19
+ :servers => '127.0.0.1:9160'
20
20
  )
21
21
  end
22
22
 
@@ -28,4 +28,4 @@ module CassandraObject
28
28
  CassandraObject::Base.connection
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class CassandraObject::Types::DecimalTypeTest < CassandraObject::TestCase
4
+ test 'encode' do
5
+ assert_equal '3.14', CassandraObject::Types::DecimalType.encode(BigDecimal.new('3.14'))
6
+ end
7
+
8
+ test 'decode' do
9
+ assert_equal BigDecimal.new('0.001'), CassandraObject::Types::DecimalType.decode('.001')
10
+ end
11
+ end
@@ -3,13 +3,13 @@ require 'test_helper'
3
3
  class CassandraObject::ValidationsTest < CassandraObject::TestCase
4
4
  test 'create!' do
5
5
  begin
6
- Issue.validates(:description, presence: true)
6
+ Issue.validates(:description, :presence => true)
7
7
 
8
- Issue.create!(description: 'lol')
8
+ Issue.create!(:description => 'lol')
9
9
 
10
- assert_raise(CassandraObject::RecordInvalid) { Issue.create!(description: '') }
10
+ assert_raise(CassandraObject::RecordInvalid) { Issue.create!(:description => '') }
11
11
  ensure
12
12
  Issue.reset_callbacks(:validate)
13
13
  end
14
14
  end
15
- end
15
+ end
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.6
4
+ version: 2.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-01 00:00:00.000000000Z
14
+ date: 2011-08-03 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
- requirement: &70162359838280 !ruby/object:Gem::Requirement
18
+ requirement: &70341720486380 !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: *70162359838280
26
+ version_requirements: *70341720486380
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cassandra
29
- requirement: &70162359837820 !ruby/object:Gem::Requirement
29
+ requirement: &70341720484280 !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: *70162359837820
37
+ version_requirements: *70341720484280
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: bundler
40
- requirement: &70162359837360 !ruby/object:Gem::Requirement
40
+ requirement: &70341720480680 !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: *70162359837360
48
+ version_requirements: *70341720480680
49
49
  description: Cassandra ActiveModel
50
50
  email: klange@sessionm.com
51
51
  executables: []
@@ -104,6 +104,7 @@ files:
104
104
  - lib/cassandra_object/types/array_type.rb
105
105
  - lib/cassandra_object/types/boolean_type.rb
106
106
  - lib/cassandra_object/types/date_type.rb
107
+ - lib/cassandra_object/types/decimal_type.rb
107
108
  - lib/cassandra_object/types/float_type.rb
108
109
  - lib/cassandra_object/types/hash_type.rb
109
110
  - lib/cassandra_object/types/integer_type.rb
@@ -127,6 +128,7 @@ files:
127
128
  - test/types/array_type_test.rb
128
129
  - test/types/boolean_type_test.rb
129
130
  - test/types/date_type_test.rb
131
+ - test/types/decimal_type_test.rb
130
132
  - test/types/float_type_test.rb
131
133
  - test/types/hash_type_test.rb
132
134
  - test/types/integer_type_test.rb
@@ -173,6 +175,7 @@ test_files:
173
175
  - test/types/array_type_test.rb
174
176
  - test/types/boolean_type_test.rb
175
177
  - test/types/date_type_test.rb
178
+ - test/types/decimal_type_test.rb
176
179
  - test/types/float_type_test.rb
177
180
  - test/types/hash_type_test.rb
178
181
  - test/types/integer_type_test.rb