extendi-cassandra_object 1.0.6 → 1.0.7

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: efe17be3c5e2444bff2078ff198a4103e590a436
4
- data.tar.gz: 5bfd5a2ec7ab2393478ca07102627d62707422b2
3
+ metadata.gz: d93715ace91da1509d264e53261d2a4b7b987cda
4
+ data.tar.gz: a479704c0f24f7285e1ef46df855d8fb8410d404
5
5
  SHA512:
6
- metadata.gz: 19d0cd635b148b38e5c9a85faab5595d65b45c94ec32387e3f7b2188e6e3cc3b5924e8bc63ad3d957ad25ab1ac5ca57cfe1d7fd02bed8429070e9c24cfa48cd0
7
- data.tar.gz: 3b63a775a8af44163f983b5d933407aa977c5e33ea92f165723909fe806c07499600fca99eee34a98c8e4e175c5d88c40a686c400f2c5a1cb8a24fd3becfb0a3
6
+ metadata.gz: 578aa46f8dd1702f6f7224c427c058804300c01da45a529ab8401ca79bd837117a8001d8f1f7d97dc11c1139ccd58fe8f1a7dd12c59e2f2f49d02644b2209ebb
7
+ data.tar.gz: 89ff7cc0bd118cd69d8be51015ab25ba5070ef4f32ccb4798583a1bc646c37756e142e72849140c966794fc32a3e4cda80556d792afa29cad66534484751de4d
data/README.md CHANGED
@@ -113,6 +113,21 @@ class Widget < CassandraObject::BaseSchema
113
113
  end
114
114
  end
115
115
  ```
116
+ ### Custom config
117
+
118
+ You can define a custom configuration for the cassandra connection, allowing you to have multiple cassandra endpoints fromt he same application
119
+
120
+ ```ruby
121
+ class Widget < CassandraObject::BaseSchema
122
+ string :name
123
+
124
+ def self.custom_config
125
+ #return custom cassandra configuration
126
+ { }
127
+ end
128
+ end
129
+ ```
130
+
116
131
  ## Using with Cassandra
117
132
 
118
133
  Add a config/cassandra.yml:
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'extendi-cassandra_object'
5
- s.version = '1.0.6'
5
+ s.version = '1.0.7'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ['Duccio Giovannelli', 'gotime']
@@ -46,7 +46,11 @@ module CassandraObject
46
46
  def where_string_async(id)
47
47
  conditions = []
48
48
  conditions << "#{@adapter.primary_key_column} = '#{id}'" if !id.nil?
49
- conditions += @scope.select_values.select { |sv| sv != :column1 }.map { |sv| 'column1 = ?' }
49
+ select_values = @scope.select_values.select { |sv| sv != :column1 }
50
+ if select_values.size > 0
51
+ select_str = select_values.size > 1 ? "column1 IN (#{select_values.map { |sv| '?' }.join(',')})" : 'column1 = ?'
52
+ conditions << select_str
53
+ end
50
54
  conditions += @scope.where_values.select.each_with_index { |_, i| i.even? }
51
55
  return conditions.any? ? "WHERE #{conditions.join(' AND ')}" : nil
52
56
  end
@@ -1,7 +1,7 @@
1
1
  module CassandraObject
2
2
  class BaseSchema < Base
3
3
  def self.adapter
4
- @adapter ||= CassandraObject::Adapters::CassandraAdapter.new(Base.config)
4
+ @adapter ||= CassandraObject::Adapters::CassandraAdapter.new(self.config)
5
5
  end
6
6
 
7
7
  def self.schema_type
@@ -1,7 +1,7 @@
1
1
  module CassandraObject
2
2
  class BaseSchemaless < Base
3
3
  def self.adapter
4
- @adapter ||= CassandraObject::Adapters::CassandraSchemalessAdapter.new(Base.config)
4
+ @adapter ||= CassandraObject::Adapters::CassandraSchemalessAdapter.new(self.config)
5
5
  end
6
6
 
7
7
  def self.schema_type
@@ -1,7 +1,7 @@
1
1
  module CassandraObject
2
2
  class BaseSchemalessDynamic < Base
3
3
  def self.adapter
4
- @adapter ||= CassandraObject::Adapters::CassandraSchemalessAdapter.new(Base.config)
4
+ @adapter ||= CassandraObject::Adapters::CassandraSchemalessAdapter.new(self.config)
5
5
  end
6
6
 
7
7
  def self.schema_type
@@ -17,6 +17,7 @@ module CassandraObject
17
17
  end
18
18
 
19
19
  def config
20
+ return self.custom_config if self.methods(false).include?(:custom_config)
20
21
  @@config
21
22
  end
22
23
 
@@ -29,6 +29,7 @@ CassandraObject::Schema.create_keyspace 'cassandra_object_test'
29
29
  CassandraObject::Schemaless.create_column_family 'Issues'
30
30
  CassandraObject::Schema.create_column_family 'IssueSchemas', {attributes: 'id text, title text, description text, field float, intero int, created_at timestamp, updated_at timestamp, PRIMARY KEY (id)', options: {}}
31
31
  CassandraObject::Schemaless.create_column_family 'IssueDynamics'
32
+ CassandraObject::Schemaless.create_column_family 'IssuesCustomConfig'
32
33
  CassandraObject::Schema.create_column_family 'IssueSchemaFathers', {attributes: 'id text, title text, field float, created_at timestamp, updated_at timestamp, PRIMARY KEY (id)', options: {}}
33
34
  CassandraObject::Schema.create_column_family 'IssueSchemaChildren', {attributes: 'id text, title text, description text, field float, created_at timestamp, updated_at timestamp, issue_schema_father_id text, PRIMARY KEY (id)', options: {}}
34
35
  CassandraObject::BaseSchemaless.adapter.consistency = :quorum
@@ -0,0 +1,33 @@
1
+ class IssueCustomConfig < CassandraObject::BaseSchemalessDynamic
2
+ string :description
3
+ string :title
4
+
5
+ before_create { self.description ||= 'funny' }
6
+
7
+ self.allow_filtering = true
8
+
9
+ def self.for_key key
10
+ where_ids(key)
11
+ end
12
+
13
+ # must be different to general config to test funcionality!
14
+ def self.custom_config
15
+ {
16
+ keyspace: 'cassandra_object_test',
17
+ hosts: ['127.0.0.1'],
18
+ compression: :lz4,
19
+ connect_timeout: 2,
20
+ timeout: 30,
21
+ consistency: :quorum,
22
+ protocol_version: 3,
23
+ page_size: 12345,
24
+ trace: true,
25
+ connections_per_local_node: 4,
26
+ schema_refresh_delay: 0.1,
27
+ schema_refresh_timeout: 0.1,
28
+ # connections_per_remote_node: nil,
29
+ # logger: Logger.new($stderr)
30
+ }
31
+ end
32
+
33
+ end
data/test/test_helper.rb CHANGED
@@ -8,6 +8,7 @@ require 'cassandra_object'
8
8
  require 'support/cassandra'
9
9
  require 'support/issue'
10
10
  require 'support/issue_dynamic'
11
+ require 'support/issue_custom_config'
11
12
  require 'support/issue_schema'
12
13
  require 'support/issue_schema_child'
13
14
  require 'support/issue_schema_father'
@@ -17,4 +17,10 @@ class CassandraObject::BaseTest < CassandraObject::TestCase
17
17
  assert_equal 'CassandraObject::BaseTest::Sons', Son.column_family
18
18
  assert_equal 'CassandraObject::BaseTest::Sons', Grandson.column_family
19
19
  end
20
+
21
+ test 'custom cassandra configuration' do
22
+ assert_equal IssueCustomConfig.config, IssueCustomConfig.custom_config
23
+ assert_not_equal CassandraObject::Base.config, IssueCustomConfig.config
24
+ end
25
+
20
26
  end
@@ -10,6 +10,15 @@ class CassandraObject::Scope::QueryMethodsTest < CassandraObject::TestCase
10
10
  assert_nil found_issue.description
11
11
  end
12
12
 
13
+ test 'multi select' do
14
+ original_issue = Issue.create title: 'foo', description: 'bar'
15
+ found_issue = Issue.select(:title, :description).find(original_issue.id)
16
+
17
+ assert_equal 'foo', found_issue.title
18
+ assert_equal 'bar', found_issue.description
19
+ assert_equal original_issue.id, found_issue.id
20
+ end
21
+
13
22
  test 'select with block' do
14
23
  foo_issue = Issue.create title: 'foo'
15
24
  Issue.create title: 'bar'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extendi-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duccio Giovannelli
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-29 00:00:00.000000000 Z
12
+ date: 2017-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -134,6 +134,7 @@ files:
134
134
  - lib/cassandra_object/validations.rb
135
135
  - test/support/cassandra.rb
136
136
  - test/support/issue.rb
137
+ - test/support/issue_custom_config.rb
137
138
  - test/support/issue_dynamic.rb
138
139
  - test/support/issue_schema.rb
139
140
  - test/support/issue_schema_child.rb