Skip to content
Browse files

remove backports dependency, use homegrown substitute for require_rel…

…ative
  • Loading branch information...
1 parent cfa6d0a commit 16615984b5b6b44569ee17b581828e7cc31618ec @slyphon slyphon committed
Showing with 50 additions and 28 deletions.
  1. +8 −5 ext/c_zookeeper.rb
  2. +2 −1 ext/zookeeper_base.rb
  3. +37 −19 lib/zookeeper.rb
  4. +2 −2 lib/zookeeper/client.rb
  5. +1 −1 zookeeper.gemspec
View
13 ext/c_zookeeper.rb
@@ -1,8 +1,11 @@
-require_relative '../lib/zookeeper/logger'
-require_relative '../lib/zookeeper/common'
-require_relative '../lib/zookeeper/constants'
-require_relative '../lib/zookeeper/exceptions' # zookeeper_c depends on exceptions defined in here
-require_relative 'zookeeper_c'
+Zookeeper.require_lib(
+ 'zookeeper/logger',
+ 'zookeeper/common',
+ 'zookeeper/constants',
+ 'zookeeper/exceptions' # zookeeper_c depends on exceptions defined in here
+)
+
+Zookeeper.require_root 'ext/zookeeper_c'
# require File.expand_path('../zookeeper_c', __FILE__)
View
3 ext/zookeeper_base.rb
@@ -1,6 +1,7 @@
-require_relative 'c_zookeeper'
require 'forwardable'
+Zookeeper.require_root 'ext/c_zookeeper'
+
# The low-level wrapper-specific methods for the C lib
# subclassed by the top-level Zookeeper class
module Zookeeper
View
56 lib/zookeeper.rb
@@ -8,29 +8,47 @@
require 'logging'
module Zookeeper
- # establishes the namespace
-end
+ ZOOKEEPER_ROOT = File.expand_path('../..', __FILE__)
-require File.expand_path('../zookeeper/core_ext', __FILE__)
+ # require a path relative to the lib directory
+ # this is to avoid monkeying explicitly with $LOAD_PATH
+ #
+ # @private
+ def self.require_lib(*relpaths)
+ relpaths.each do |relpath|
+ require File.join(ZOOKEEPER_ROOT, 'lib', relpath)
+ end
+ end
-require 'backports' if RUBY_VERSION =~ /\A1\.8\./
+ # require a path that's relative to ZOOKEEPER_ROOT
+ # @private
+ def self.require_root(*relpaths)
+ relpaths.each do |relpath|
+ require File.join(ZOOKEEPER_ROOT, relpath)
+ end
+ end
+end
-require_relative 'zookeeper/monitor'
-require_relative 'zookeeper/logger'
-require_relative 'zookeeper/forked'
-require_relative 'zookeeper/latch'
-require_relative 'zookeeper/acls'
-require_relative 'zookeeper/constants'
-require_relative 'zookeeper/exceptions'
-require_relative 'zookeeper/continuation'
-require_relative 'zookeeper/common'
-require_relative 'zookeeper/callbacks'
-require_relative 'zookeeper/stat'
-require_relative 'zookeeper/client_methods'
+Zookeeper.require_lib(
+ 'zookeeper/core_ext',
+ 'zookeeper/monitor',
+ 'zookeeper/logger',
+ 'zookeeper/forked',
+ 'zookeeper/latch',
+ 'zookeeper/acls',
+ 'zookeeper/constants',
+ 'zookeeper/exceptions',
+ 'zookeeper/continuation',
+ 'zookeeper/common',
+ 'zookeeper/callbacks',
+ 'zookeeper/stat',
+ 'zookeeper/client_methods'
+)
+
+#require 'backports' if RUBY_VERSION =~ /\A1\.8\./
# ok, now we construct the client
-
-require_relative 'zookeeper/client'
+Zookeeper.require_lib 'zookeeper/client'
module Zookeeper
include Constants
@@ -90,7 +108,7 @@ class << self
end
# just for first test, get rid of this soon
-require_relative 'zookeeper/compatibility'
+Zookeeper.require_lib 'zookeeper/compatibility'
if ENV['ZKRB_DEBUG']
Zookeeper.debug_level = Zookeeper::Constants::ZOO_LOG_LEVEL_DEBUG
View
4 lib/zookeeper/client.rb
@@ -3,9 +3,9 @@
# or which class we're subclassing.
if defined?(::JRUBY_VERSION)
- require_relative('../../java/java_base')
+ Zookeeper.require_root('java/java_base')
else
- require_relative('../../ext/zookeeper_base')
+ Zookeeper.require_root('ext/zookeeper_base')
end
View
2 zookeeper.gemspec
@@ -20,7 +20,7 @@ This library uses version #{Zookeeper::DRIVER_VERSION} of zookeeper bindings.
s.homepage = 'https://github.com/slyphon/zookeeper'
- s.add_runtime_dependency 'backports', '~> 2.5.1'
+ # s.add_runtime_dependency 'backports', '~> 2.5.1'
s.add_runtime_dependency 'logging', '~> 1.7.2'
s.files = `git ls-files`.split("\n")

0 comments on commit 1661598

Please sign in to comment.
Something went wrong with that request. Please try again.