Class: WPPlugin

Inherits:
Object
  • Object
show all
Defined in:
lib/wpplugin.rb

Constant Summary collapse

VERSION =
'0.1'

Instance Method Summary collapse

Constructor Details

#initializeWPPlugin

Returns a new instance of WPPlugin.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/wpplugin.rb', line 27

def initialize
	command = ARGV.shift
	command = command.to_sym unless command.nil?
	plugin = ARGV.shift
	plugin = plugin.dup.to_str unless plugin.nil?
	if !plugin.nil?
		plugin.downcase
		plugin.gsub! ".", ""
		plugin.gsub! "/", ""
		plugin.gsub! " ", ""
	end
	plugin = nil if !plugin.nil? and plugin.empty?
	case command
		when :"--v", :"--version"
			info
		when nil, :"--help", :"-h"
			exit_message "Usage: wpplugin update\n       wpplugin [update|add|remove] {plugin-slug}"
		when :add, :remove
			exit_error_message "You must provide a plugin slug" if plugin.nil?
			send command, plugin
		when :update, :upgrade
			if plugin.nil?
				update_all
			else
				update plugin
			end
		else
			exit_error_message "Invalid command"
	end
end

Instance Method Details

#add(plugin) ⇒ Object



69
70
71
72
73
74
# File 'lib/wpplugin.rb', line 69

def add plugin
	uri = "http://downloads.wordpress.org/plugin/#{plugin}.latest-stable.zip"
	`wget -O #{plugin}.zip #{uri} > /dev/null 2>&1`
	`unzip #{plugin}.zip > /dev/null 2>&1`
	`rm #{plugin}.zip > /dev/null 2>&1`
end

#debug(message) ⇒ Object



84
85
86
# File 'lib/wpplugin.rb', line 84

def debug message
	puts message if @debug
end

#exit_error_message(message) ⇒ Object



93
94
95
# File 'lib/wpplugin.rb', line 93

def exit_error_message message
	exit_message '[ERROR] ' + message
end

#exit_message(message) ⇒ Object



88
89
90
91
# File 'lib/wpplugin.rb', line 88

def exit_message message
	puts message
	exit
end

#infoObject



80
81
82
# File 'lib/wpplugin.rb', line 80

def info
	puts "WPPlugin #{self.class::VERSION}"
end

#remove(plugin) ⇒ Object



76
77
78
# File 'lib/wpplugin.rb', line 76

def remove plugin
	FileUtils.rm_rf plugin if File.directory? plugin
end

#update(plugin) ⇒ Object



58
59
60
61
# File 'lib/wpplugin.rb', line 58

def update plugin
	remove plugin
	add plugin
end

#update_allObject



63
64
65
66
67
# File 'lib/wpplugin.rb', line 63

def update_all
	plugins = Pathname.glob("*/readme.txt").map { |i| i.dirname.to_s }.each do |plugin|
		update plugin
	end
end