gotime-cassandra_object 4.3.2 → 4.4.0

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 = '4.3.2'
5
+ s.version = '4.4.0'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
@@ -29,6 +29,7 @@ module CassandraObject
29
29
  extend ActiveSupport::DescendantsTracker
30
30
 
31
31
  include Connection
32
+ include Consistency
32
33
  include Identity
33
34
  include Inspect
34
35
  include Persistence
@@ -0,0 +1,18 @@
1
+ module CassandraObject
2
+ module Consistency
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def with_consistency(consistency)
7
+ previous, self.default_consistency = default_consistency, consistency
8
+ yield
9
+ ensure
10
+ self.default_consistency = previous
11
+ end
12
+ end
13
+
14
+ included do
15
+ class_attribute :default_consistency
16
+ end
17
+ end
18
+ end
@@ -24,7 +24,7 @@ module CassandraObject
24
24
  yield records
25
25
  break if next_record.nil?
26
26
 
27
- records = scope.where("KEY >= #{next_record.id}").to_a
27
+ records = scope.where("KEY >= '#{next_record.id}'").to_a
28
28
  end
29
29
  end
30
30
  end
@@ -20,7 +20,8 @@ module CassandraObject
20
20
  end
21
21
 
22
22
  def first
23
- limit(1).to_a.first
23
+ to_a.first
24
+ # limit(1).to_a.first
24
25
  end
25
26
 
26
27
  private
@@ -36,7 +36,8 @@ module CassandraObject
36
36
  statement = [
37
37
  "SELECT #{select_string} FROM #{klass.column_family}",
38
38
  where_string,
39
- limit_string
39
+ limit_string,
40
+ consistency_string
40
41
  ].delete_if(&:blank?) * ' '
41
42
 
42
43
  instantiate_from_cql(statement)
@@ -97,6 +98,12 @@ module CassandraObject
97
98
  ""
98
99
  end
99
100
  end
101
+
102
+ def consistency_string
103
+ if klass.default_consistency
104
+ "USING CONSISTENCY #{klass.default_consistency}"
105
+ end
106
+ end
100
107
  end
101
108
  end
102
109
  end
@@ -7,6 +7,7 @@ module CassandraObject
7
7
 
8
8
  autoload :Base
9
9
  autoload :Connection
10
+ autoload :Consistency
10
11
  autoload :AttributeMethods
11
12
  autoload :BelongsTo
12
13
  autoload :Persistence
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class CassandraObject::ConsistencyTest < CassandraObject::TestCase
4
+ test "with_consistency" do
5
+ assert_nil CassandraObject::Base.default_consistency
6
+
7
+ CassandraObject::Base.with_consistency 'QUORUM' do
8
+ assert_equal 'QUORUM', CassandraObject::Base.default_consistency
9
+ end
10
+
11
+ assert_nil CassandraObject::Base.default_consistency
12
+ end
13
+ end
@@ -16,4 +16,10 @@ class CassandraObject::Scope::QueryMethodsTest < CassandraObject::TestCase
16
16
 
17
17
  assert_equal [foo_issue], Issue.select { |issue| issue.title == 'foo' }
18
18
  end
19
+
20
+ test "select with consistency" do
21
+ Issue.with_consistency 'ONE' do
22
+ Issue.all
23
+ end
24
+ end
19
25
  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: 4.3.2
4
+ version: 4.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-14 00:00:00.000000000 Z
13
+ date: 2012-09-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -104,6 +104,7 @@ files:
104
104
  - lib/cassandra_object/belongs_to/reflection.rb
105
105
  - lib/cassandra_object/callbacks.rb
106
106
  - lib/cassandra_object/connection.rb
107
+ - lib/cassandra_object/consistency.rb
107
108
  - lib/cassandra_object/errors.rb
108
109
  - lib/cassandra_object/identity.rb
109
110
  - lib/cassandra_object/inspect.rb
@@ -150,6 +151,7 @@ files:
150
151
  - test/unit/belongs_to_test.rb
151
152
  - test/unit/callbacks_test.rb
152
153
  - test/unit/connection_test.rb
154
+ - test/unit/consistency_test.rb
153
155
  - test/unit/identity_test.rb
154
156
  - test/unit/inspect_test.rb
155
157
  - test/unit/log_subscriber_test.rb