Skip to content

Commit c635165

Browse files
author
Bulat Shakirzyanov
committed
[RUBY-119] allow avoiding namespace conflicts
1 parent 675ac9c commit c635165

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Features:
44

5+
* [RUBY-119] Use `require 'datastax/cassandra'` to avoid namespace conflicts
56
* [RUBY-90] Add support for disabling nagle algorithm (tcp nodelay), enabled by default.
67
* [RUBY-70] Add support for client-side timestamps, disabled by default.
78
* [RUBY-114] Add support for serial consistency in batch requests.

features/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ DSE before 3.1 uses a non-standard protocol and is not currently supported.
389389

390390
Port 9160 is the old Thrift interface, the binary protocol runs on 9042. This is also the default port for ruby-driver, so unless you've changed the port in `cassandra.yaml`, don't override the port.
391391

392+
### I get namespace conflicts with another gem
393+
394+
Use `require 'datastax/cassandra'` and `DataStax::Cassandra` to get a namespaced version of the gem and prevent conflicts with other gems that use top level `Cassandra` namespace.
395+
392396
### Something else is not working
393397

394398
Open an issue and someone will try to help you out. Please include the gem version, Casandra version and Ruby version, and explain as much about what you're doing as you can, preferably the smallest piece of code that reliably triggers the problem. The more information you give, the better the chances you will get help.

lib/datastax/cassandra.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# encoding: utf-8
2+
3+
#--
4+
# Copyright 2013-2015 DataStax, Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#++
18+
19+
module DataStax
20+
@base = __FILE__ + '/../..'
21+
22+
def self.require(path)
23+
if path.start_with?('cassandra/')
24+
include(path)
25+
else
26+
::Kernel.require(path)
27+
end
28+
end
29+
30+
def self.include(path)
31+
path = File.expand_path(path + '.rb', @base)
32+
class_eval(File.read(path), path, 1)
33+
end
34+
35+
include 'cassandra'
36+
end

0 commit comments

Comments
 (0)