sessionm-cassandra_object 4.0.5 → 4.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4355a6422c75d897dd919952f07b87dabfd8a542
4
- data.tar.gz: 4ef8a17c0c792362b827f6751321fc68f1152b51
3
+ metadata.gz: 539bceeb4486ffdd621cb72f76d716f870f4e18a
4
+ data.tar.gz: 45e22b538f31d1c1657be029fac182f8e16b618f
5
5
  SHA512:
6
- metadata.gz: 91b46f858386b3986381750dceee7c0c1cbac2212e8752678ca1c48fe9b54c95a2a7c74370bf57b5c6dbe01d992f4c7d9eaf2727e7f3c31c38e71f704d4be88d
7
- data.tar.gz: b55520ae9c9a8d5a080d80ee6b28e342243971fe2ad820501b8a909fbac79b77ad9d9fe97230e701d9740ddb3063afcae556f73cd12c61db816ee5b15f929ff4
6
+ metadata.gz: 85e074b00d7e502eb1b7e20d42dd2b6b47a4cd2de6e5dc324612636f3db5c9f130d17ca4d9f3d7aa3ff667efc16fe817ef819158a449e7c1b923a71e43674bff
7
+ data.tar.gz: e2d391a541f081c3e262ecd61eeeeff0144c7cdce355873795800578818559eee845170baf132d54549252358c1ac6114a656413d495d8d68ef5b3fa28b325c9
@@ -108,13 +108,15 @@ module CassandraObject
108
108
  end
109
109
  end
110
110
 
111
- def add(column_family, key, by, field, opts=nil)
111
+ def add(column_family, key, by, fields, opts=nil)
112
112
  async = opts.try(:[], :async)
113
+ fields = [fields] unless fields.is_a?(Array)
113
114
  key = "textAsBlob('#{key}')"
114
115
 
115
- query = "UPDATE \"#{column_family}\" SET #{VALUE_FIELD} = #{VALUE_FIELD} + #{by} WHERE #{KEY_FIELD} = #{key} AND #{NAME_FIELD} = '#{field}';"
116
-
117
- async ? self.execute_async(query, execute_options(opts)) : self.execute(query, execute_options(opts))
116
+ fields.each do |field|
117
+ query = "UPDATE \"#{column_family}\" SET #{VALUE_FIELD} = #{VALUE_FIELD} + #{by} WHERE #{KEY_FIELD} = #{key} AND #{NAME_FIELD} = '#{field}';"
118
+ async ? self.execute_async(query, execute_options(opts)) : self.execute(query, execute_options(opts))
119
+ end
118
120
  end
119
121
 
120
122
  def remove(column_family, key, *args)
@@ -168,6 +170,10 @@ module CassandraObject
168
170
  def schema_cache
169
171
  @schema_cache ||= SchemaCache.new(self)
170
172
  end
173
+
174
+ def column_families
175
+ @column_families ||= self.cluster.keyspace(session.keyspace).tables.inject({}) { |hsh, table| hsh[table.name] = table; hsh }
176
+ end
171
177
  end
172
178
  end
173
179
  end
@@ -3,14 +3,10 @@ module CassandraObject
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def add(key, value, *columns_and_options)
7
- column_family, column, sub_column, options = CassandraObject::Base.with_connection(key, :write) { connection.extract_and_validate_params(self.column_family, key, columns_and_options, {}) }
8
- # the options are removed, leaving just columns
9
- columns = columns_and_options
10
-
6
+ def add(key, value, *columns)
11
7
  CassandraObject::Base.with_connection(key, :write) do
12
- ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column, sub_column: sub_column, value: value) do
13
- connection.add(column_family, key, value, *columns, :consistency => thrift_write_consistency)
8
+ ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: columns, value: value) do
9
+ connection.add(column_family, key, value, columns, :consistency => thrift_write_consistency)
14
10
  end
15
11
  end
16
12
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '4.0.5'
5
+ s.version = '4.0.6'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe CassandraObject::Adapters::CassandraDriver do
4
+ context "Client" do
5
+ it "should return the column family definition by name" do
6
+ expect(Issue.connection.column_families['Issues'].present?).to be true
7
+ expect(Issue.connection.column_families['Unknowns'].present?).to be false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe CassandraObject::Persistence do
4
+ context "add" do
5
+ it "should increment the counter" do
6
+ id = SimpleUUID::UUID.new.to_guid
7
+ Counter.add id, 1, 'foo'
8
+ expect(Counter.get_counter(id, 'foo')).to eq 1
9
+ Counter.add id, 1, 'foo'
10
+ expect(Counter.get_counter(id, 'foo')).to eq 2
11
+ end
12
+ end
13
+ 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: 4.0.5
4
+ version: 4.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Koziarski
@@ -96,8 +96,10 @@ files:
96
96
  - lib/cassandra_object/validations.rb
97
97
  - script/console.rb
98
98
  - sessionm-cassandra_object.gemspec
99
+ - spec/cassandra_object/adapters/cassandra_driver_spec.rb
99
100
  - spec/cassandra_object/associations_spec.rb
100
101
  - spec/cassandra_object/base_spec.rb
102
+ - spec/cassandra_object/persistence_spec.rb
101
103
  - spec/spec_helper.rb
102
104
  - spec/support/cassandra.rb
103
105
  - spec/support/db/migrate/001_create_test_tables.rb
@@ -154,8 +156,10 @@ signing_key:
154
156
  specification_version: 4
155
157
  summary: Cassandra ActiveModel
156
158
  test_files:
159
+ - spec/cassandra_object/adapters/cassandra_driver_spec.rb
157
160
  - spec/cassandra_object/associations_spec.rb
158
161
  - spec/cassandra_object/base_spec.rb
162
+ - spec/cassandra_object/persistence_spec.rb
159
163
  - spec/spec_helper.rb
160
164
  - spec/support/cassandra.rb
161
165
  - spec/support/db/migrate/001_create_test_tables.rb