aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/quiet_opener.rb37
-rw-r--r--lib/tasks/themes.rake26
2 files changed, 47 insertions, 16 deletions
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}")
diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake
index 78ffe73be..65b142a63 100644
--- a/lib/tasks/themes.rake
+++ b/lib/tasks/themes.rake
@@ -9,6 +9,14 @@ namespace :themes do
File.join(plugin_dir, theme_name)
end
+ def old_theme_dir(theme_name)
+ File.join(Rails.root, "vendor", "plugins", theme_name)
+ end
+
+ def possible_theme_dirs(theme_name)
+ [theme_dir(theme_name), old_theme_dir(theme_name)]
+ end
+
def checkout(commitish)
puts "Checking out #{commitish}" if verbose
system "git checkout #{commitish}"
@@ -61,13 +69,14 @@ namespace :themes do
end
def uninstall(theme_name, verbose=false)
- dir = theme_dir(theme_name)
- if File.directory?(dir)
- run_hook(theme_name, 'uninstall', verbose)
- puts "Removing '#{dir}'" if verbose
- rm_r dir
- else
- puts "Plugin doesn't exist: #{dir}"
+ possible_theme_dirs(theme_name).each do |dir|
+ if File.directory?(dir)
+ run_hook(theme_name, 'uninstall', verbose)
+ puts "Removing '#{dir}'" if verbose
+ rm_r dir
+ else
+ puts "Plugin doesn't exist: #{dir}"
+ end
end
end
@@ -80,10 +89,11 @@ namespace :themes do
end
def installed?(theme_name)
- File.directory?(theme_dir(theme_name))
+ possible_theme_dirs(theme_name).any? { |dir| File.directory? dir }
end
def install_theme(theme_url, verbose, deprecated=false)
+ FileUtils.mkdir_p plugin_dir
deprecation_string = deprecated ? " using deprecated THEME_URL" : ""
theme_name = theme_url_to_theme_name theme_url
puts "Installing theme #{theme_name}#{deprecation_string} from #{theme_url}"