]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/libraries/wordpress.rb
Fix issues reported by new rubocop
[chef.git] / cookbooks / wordpress / libraries / wordpress.rb
1 require "chef/mixin/command"
2
3 class Chef
4   module Wordpress
5     extend Chef::Mixin::Command
6
7     @api_responses = {}
8     @svn_responses = {}
9
10     class << self
11       def current_version
12         core_version_check["offers"].first["current"]
13       end
14
15       def current_plugin_version(name)
16         if svn_cat("http://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/
17           Regexp.last_match[1]
18         else
19           "trunk"
20         end
21       end
22
23       private
24
25       def core_version_check
26         api_get("http://api.wordpress.org/core/version-check/1.6")
27       end
28
29       def api_get(url)
30         @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url))
31       end
32
33       def svn_cat(url)
34         unless @svn_responses[url]
35           status, stdout, stderr = output_of_command("svn cat #{url}", {})
36           handle_command_failures(status, "STDOUT: #{stdout}\nSTDERR: #{stderr}", :output_on_failure => true)
37
38           @svn_responses[url] = stdout.force_encoding("UTF-8")
39         end
40
41         @svn_responses[url]
42       end
43     end
44   end
45 end