gotime-cassandra_object 2.4.2 → 2.5.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.
data/README.rdoc CHANGED
@@ -12,9 +12,9 @@ Add the following to your Gemfile:
12
12
 
13
13
  class Widget < CassandraObject::Base
14
14
  key :uuid
15
- attribute :name, type: :string
16
- attribute :description, type: :string
17
- attribute :price, type: :integer
15
+ string :name
16
+ string :description
17
+ integer :price
18
18
 
19
19
  validates :name, presence: :true
20
20
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '2.4.2'
5
+ s.version = '2.5.0'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -17,6 +17,21 @@ module CassandraObject
17
17
  extend ActiveSupport::Concern
18
18
  include ActiveModel::AttributeMethods
19
19
 
20
+ included do
21
+ class_attribute :model_attributes
22
+ self.model_attributes = {}.with_indifferent_access
23
+
24
+ attribute_method_suffix("", "=")
25
+
26
+ %w(array boolean date float integer time time_with_zone set string).each do |type|
27
+ instance_eval <<-EOV, __FILE__, __LINE__ + 1
28
+ def #{type}(name, options = {}) # def string(name, options = {})
29
+ attribute(name, options.update(type: :#{type})) # attribute(name, options.update(type: :string))
30
+ end # end
31
+ EOV
32
+ end
33
+ end
34
+
20
35
  module ClassMethods
21
36
  def inherited(child)
22
37
  super
@@ -42,13 +57,6 @@ module CassandraObject
42
57
  end
43
58
  end
44
59
 
45
- included do
46
- class_attribute :model_attributes
47
- self.model_attributes = {}.with_indifferent_access
48
-
49
- attribute_method_suffix("", "=")
50
- end
51
-
52
60
  def write_attribute(name, value)
53
61
  if ma = self.class.model_attributes[name]
54
62
  @attributes[name.to_s] = ma.check_value!(value)
@@ -7,5 +7,4 @@ CassandraObject::Type.register(:integer, Integer, CassandraObject::Types::Intege
7
7
  CassandraObject::Type.register(:set, Array, CassandraObject::Types::SetType)
8
8
  CassandraObject::Type.register(:time, Time, CassandraObject::Types::TimeType)
9
9
  CassandraObject::Type.register(:time_with_zone, ActiveSupport::TimeWithZone, CassandraObject::Types::TimeWithZoneType)
10
- CassandraObject::Type.register(:string, String, CassandraObject::Types::UTF8StringType) #This could be changed to StringType to support non-utf8 strings
11
- CassandraObject::Type.register(:utf8, String, CassandraObject::Types::UTF8StringType)
10
+ CassandraObject::Type.register(:string, String, CassandraObject::Types::StringType)
@@ -17,4 +17,4 @@ module CassandraObject
17
17
  end
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -7,7 +7,7 @@ module CassandraObject
7
7
  end
8
8
 
9
9
  def decode(str)
10
- str
10
+ str.force_encoding('UTF-8')
11
11
  end
12
12
  end
13
13
  end
@@ -41,9 +41,9 @@ module CassandraObject
41
41
  autoload :HashType
42
42
  autoload :IntegerType
43
43
  autoload :SetType
44
+ autoload :StringType
44
45
  autoload :TimeType
45
46
  autoload :TimeWithZoneType
46
- autoload :UTF8StringType
47
47
  end
48
48
  end
49
49
 
@@ -6,7 +6,7 @@ class CassandraObject::AttributesTest < CassandraObject::TestCase
6
6
  end
7
7
 
8
8
  class TestChildIssue < TestIssue
9
- attribute :description, type: :string
9
+ string :description
10
10
  end
11
11
 
12
12
  test 'attributes not shared' do
@@ -4,7 +4,7 @@ class CassandraObject::CallbacksTest < CassandraObject::TestCase
4
4
  class TestIssue < CassandraObject::Base
5
5
  self.column_family = 'Issues'
6
6
  key :uuid
7
- attribute :description, type: :string
7
+ string :description
8
8
 
9
9
  %w(after_save after_create after_update after_destroy).each do |method|
10
10
  send(method) do
data/test/test_helper.rb CHANGED
@@ -6,7 +6,7 @@ require 'gotime-cassandra_object'
6
6
 
7
7
  class Issue < CassandraObject::Base
8
8
  key :uuid
9
- attribute :description, type: :string
9
+ string :description
10
10
  end
11
11
 
12
12
  module CassandraObject
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.4.2
4
+ version: 2.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2011-08-26 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &70186624012980 !ruby/object:Gem::Requirement
17
+ requirement: &70322955465140 !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: *70186624012980
25
+ version_requirements: *70322955465140
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cassandra
28
- requirement: &70186624012360 !ruby/object:Gem::Requirement
28
+ requirement: &70322955464620 !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: *70186624012360
36
+ version_requirements: *70322955464620
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &70186624011700 !ruby/object:Gem::Requirement
39
+ requirement: &70322955464020 !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: *70186624011700
47
+ version_requirements: *70322955464020
48
48
  description: Cassandra ActiveModel
49
49
  email: gems@gotime.com
50
50
  executables: []
@@ -110,7 +110,6 @@ files:
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
113
- - lib/cassandra_object/types/utf8_string_type.rb
114
113
  - lib/cassandra_object/validations.rb
115
114
  - lib/gotime-cassandra_object.rb
116
115
  - test/active_model_test.rb
@@ -135,7 +134,6 @@ files:
135
134
  - test/types/set_type_test.rb
136
135
  - test/types/string_type_test.rb
137
136
  - test/types/time_type_test.rb
138
- - test/types/utf8_string_type_test.rb
139
137
  - test/validations_test.rb
140
138
  homepage: http://github.com/gotime/cassandra_object
141
139
  licenses: []
@@ -184,5 +182,4 @@ test_files:
184
182
  - test/types/set_type_test.rb
185
183
  - test/types/string_type_test.rb
186
184
  - test/types/time_type_test.rb
187
- - test/types/utf8_string_type_test.rb
188
185
  - test/validations_test.rb
@@ -1,16 +0,0 @@
1
- module CassandraObject
2
- module Types
3
- class UTF8StringType
4
- def encode(str)
5
- # This is technically the most correct, but it is a pain to require utf-8 encoding for all strings. Should revisit.
6
- #raise ArgumentError.new("#{self} requires a UTF-8 encoded String") unless str.kind_of?(String) && str.encoding == Encoding::UTF_8
7
- raise ArgumentError.new("#{self} requires a String") unless str.kind_of?(String)
8
- str.dup
9
- end
10
-
11
- def decode(str)
12
- str.force_encoding('UTF-8')
13
- end
14
- end
15
- end
16
- end
@@ -1,4 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CassandraObject::Type::BooleanTypeTest < CassandraObject::Types::TestCase
4
- end