X-Git-Url: https://git.openstreetmap.org/chef.git/blobdiff_plain/2c854e9952890a119750a187479eb2701107705f..03b506e71ad2cdacbb6f24faaa8f839561a2b312:/cookbooks/wordpress/libraries/wordpress.rb diff --git a/cookbooks/wordpress/libraries/wordpress.rb b/cookbooks/wordpress/libraries/wordpress.rb index 8ebb1460c..e83ba0417 100644 --- a/cookbooks/wordpress/libraries/wordpress.rb +++ b/cookbooks/wordpress/libraries/wordpress.rb @@ -1,4 +1,7 @@ -require 'chef/mixin/command' +require "chef/mixin/command" + +require "httpclient" +require "php_serialize" class Chef module Wordpress @@ -7,37 +10,39 @@ class Chef @api_responses = {} @svn_responses = {} - def self.current_version - core_version_check["offers"].first["current"] - end + class << self + def current_version + core_version_check["offers"].first["current"] + end - def self.current_plugin_version(name) - if svn_cat("http://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/ - $1 - else - "trunk" + def current_plugin_version(name) + if svn_cat("http://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/ + Regexp.last_match[1] + else + "trunk" + end end - end - private + private - def self.core_version_check - api_get("http://api.wordpress.org/core/version-check/1.6") - end + def core_version_check + api_get("http://api.wordpress.org/core/version-check/1.6") + end - def self.api_get(url) - @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url)) - end + def api_get(url) + @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url)) + end - def self.svn_cat(url) - unless @svn_responses[url] - status, stdout, stderr = output_of_command("svn cat #{url}", {}) - handle_command_failures(status, "STDOUT: #{stdout}\nSTDERR: #{stderr}", :output_on_failure => true) + def svn_cat(url) + unless @svn_responses[url] + status, stdout, stderr = output_of_command("svn cat #{url}", {}) + handle_command_failures(status, "STDOUT: #{stdout}\nSTDERR: #{stderr}", :output_on_failure => true) - @svn_responses[url] = stdout.force_encoding("UTF-8") - end + @svn_responses[url] = stdout.force_encoding("UTF-8") + end - @svn_responses[url] + @svn_responses[url] + end end end end