diff options
-rw-r--r-- | .ruby-version | 2 | ||||
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | Gemfile.lock | 6 | ||||
-rw-r--r-- | lib/quiet_opener.rb | 37 |
5 files changed, 38 insertions, 11 deletions
diff --git a/.ruby-version b/.ruby-version index 2aaf2528c..7fa1d1ef4 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-1.9.3-p392 +2.0.0-p353 diff --git a/.travis.yml b/.travis.yml index 051dc0fae..d6ed72cf6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ branches: rvm: - 1.8.7 - 1.9.3 + - 2.0.0 before_install: - gem install rake --version=0.9.2.2 - git submodule update --init --recursive @@ -23,7 +23,7 @@ gem 'jquery-ui-rails' gem 'json' gem 'mahoro' gem 'memcache-client' -gem 'net-http-local' +gem 'net-http-local', :platforms => [:ruby_18, :ruby_19] gem 'net-purge' gem 'newrelic_rpm' gem 'rack' @@ -77,6 +77,7 @@ end group :develop do gem 'ruby-debug', :platforms => :ruby_18 gem 'debugger', :platforms => :ruby_19 + gem 'byebug', :platforms => :ruby_20 gem 'annotate' end diff --git a/Gemfile.lock b/Gemfile.lock index 6c0c99eeb..c5c1fa3b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,6 +51,9 @@ GEM bootstrap-sass (2.3.1.2) sass (~> 3.2) builder (3.0.4) + byebug (2.3.1) + columnize (~> 0.3.6) + debugger-linecache (~> 1.2.0) capistrano (2.15.4) highline net-scp (>= 1.0.0) @@ -261,7 +264,7 @@ GEM multi_json (~> 1.0, >= 1.0.2) unicode (0.4.4) unidecoder (1.1.2) - vpim (0.695) + vpim (13.11.11) webrat (0.7.3) nokogiri (>= 1.2.0) rack (>= 1.0) @@ -278,6 +281,7 @@ DEPENDENCIES acts_as_versioned! annotate bootstrap-sass + byebug capistrano charlock_holmes coffee-rails (~> 3.2.1) diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index ae6605c43..16ea27b8e 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -1,6 +1,8 @@ require 'open-uri' require 'net-purge' -require 'net/http/local' +if RUBY_VERSION.to_f < 2.0 + require 'net/http/local' +end def quietly_try_to_open(url) begin @@ -12,17 +14,36 @@ def quietly_try_to_open(url) return result end +# On Ruby versions before 2.0, we need to use the net-http-local gem +# to force the use of 127.0.0.1 as the local interface for the +# connection. However, at the time of writing this gem doesn't work +# on Ruby 2.0 and it's not necessary with that Ruby version - one can +# supply a :local_host option to Net::HTTP:start. So, this helper +# function is to abstract away that difference, and can be used as you +# would Net::HTTP.start(host) when passed a block. +def http_from_localhost(host) + if RUBY_VERSION.to_f >= 2.0 + Net::HTTP.start(host, :local_host => '127.0.0.1') do |http| + yield http + end + else + Net::HTTP.bind '127.0.0.1' do + Net::HTTP.start(host) do |http| + yield http + end + end + end +end + def quietly_try_to_purge(host, url) begin result = "" result_body = "" - Net::HTTP.bind '127.0.0.1' do - Net::HTTP.start(host) {|http| - request = Net::HTTP::Purge.new(url) - response = http.request(request) - result = response.code - result_body = response.body - } + http_from_localhost(host) do |http| + request = Net::HTTP::Purge.new(url) + response = http.request(request) + result = response.code + result_body = response.body end rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET, Errno::ENETUNREACH Rails.logger.warn("PURGE: Unable to reach host #{host}") |