THRIFT-372. rb: Ruby lib doesn't rescue properly from lack of native_thrift extension
This patch adds a new thrift/thrift_native.rb which should be the require point for application users. It also removes some unnecessary code from a few files and cleans up requires in some specs.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@758794 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/lib/thrift.rb b/lib/rb/lib/thrift.rb
index d3fe7ab..ec15adc 100644
--- a/lib/rb/lib/thrift.rb
+++ b/lib/rb/lib/thrift.rb
@@ -19,11 +19,6 @@
$:.unshift File.dirname(__FILE__)
-module Thrift
- # prevent the deprecation layer from being loaded if you require 'thrift'
- DEPRECATION = false unless const_defined? :DEPRECATION
-end
-
require 'thrift/core_ext'
require 'thrift/exceptions'
require 'thrift/types'
@@ -32,6 +27,8 @@
require 'thrift/struct'
require 'thrift/protocol'
require 'thrift/protocol/binaryprotocol'
+require 'thrift/protocol/compact_protocol'
require 'thrift/transport'
require 'thrift/transport/socket'
require 'thrift/server'
+require "thrift/thrift_native"
\ No newline at end of file
diff --git a/lib/rb/lib/thrift/thrift_native.rb b/lib/rb/lib/thrift/thrift_native.rb
new file mode 100644
index 0000000..c7fd252
--- /dev/null
+++ b/lib/rb/lib/thrift/thrift_native.rb
@@ -0,0 +1,5 @@
+begin
+ require "thrift_native"
+rescue LoadError
+ puts "Unable to load thrift_native extension. Defaulting to pure Ruby libraries."
+end
\ No newline at end of file
diff --git a/lib/rb/spec/protocol_spec.rb b/lib/rb/spec/protocol_spec.rb
index 1db4e19..443c8f0 100644
--- a/lib/rb/spec/protocol_spec.rb
+++ b/lib/rb/spec/protocol_spec.rb
@@ -1,5 +1,4 @@
require File.dirname(__FILE__) + '/spec_helper'
-require "thrift_native"
class ThriftProtocolSpec < Spec::ExampleGroup
include Thrift
diff --git a/lib/rb/spec/spec_helper.rb b/lib/rb/spec/spec_helper.rb
index 30b9da7..3fbd673 100644
--- a/lib/rb/spec/spec_helper.rb
+++ b/lib/rb/spec/spec_helper.rb
@@ -9,13 +9,6 @@
# will get screwed up
# $" << 'fastthread.bundle'
-# turn on deprecation so we can test it
-module Thrift
- # squelch any warnings if we happen to get required twice
- remove_const(:DEPRECATION) if const_defined? :DEPRECATION
- DEPRECATION = true
-end
-
require File.dirname(__FILE__) + '/../lib/thrift'
class Object
@@ -32,9 +25,6 @@
end
end
-require "thrift/protocol/compact_protocol"
-require "thrift_native"
-
require File.dirname(__FILE__) + "/../debug_proto_test/gen-rb/Srv"
module Fixtures