Class: Deployku::Plugin
- Inherits:
-
Object
- Object
- Deployku::Plugin
- Defined in:
- lib/deployku/plugins.rb
Direct Known Subclasses
AccessPlugin, AppPlugin, DockerEngine, GitPlugin, LxcEngine, NginxPlugin, PostgresPlugin, RailsPlugin, RedisPlugin
Defined Under Namespace
Classes: NoMethod
Class Attribute Summary collapse
-
.plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Class Method Summary collapse
- .<<(plugin) ⇒ Object
- .command_description(fn) ⇒ Object
- .filter_plugins(fn) ⇒ Object
- .find_plugin(name) ⇒ Object
-
.help ⇒ Object
collects info from ‘describe’ and returns it as a string.
- .inherited(plugin) ⇒ Object
- .instance ⇒ Object
-
.run(fn, args = []) ⇒ Object
run command in a plugin.
Instance Method Summary collapse
-
#packages ⇒ Object
concatenate system wide packages and packages required by plugin.
Class Attribute Details
.plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
10 11 12 |
# File 'lib/deployku/plugins.rb', line 10 def plugins @plugins end |
Class Method Details
.<<(plugin) ⇒ Object
13 14 15 |
# File 'lib/deployku/plugins.rb', line 13 def self.<<(plugin) @plugins << plugin end |
.command_description(fn) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/deployku/plugins.rb', line 97 def self.command_description(fn) self.help_register.each do |reg| return reg if reg[:name].to_s == fn.to_s end nil end |
.filter_plugins(fn) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/deployku/plugins.rb', line 25 def self.filter_plugins(fn) plugins = [] @plugins.each do |plugin| plug = plugin.instance plugins << plug if plug.respond_to?(fn) end plugins end |
.find_plugin(name) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/deployku/plugins.rb', line 17 def self.find_plugin(name) plugin_name = "Deployku::#{name.capitalize}Plugin" @plugins.each do |plugin| return plugin if plugin.name == plugin_name end nil end |
.help ⇒ Object
collects info from ‘describe’ and returns it as a string
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/deployku/plugins.rb', line 48 def self.help str = '' help_register = [] max_name_length = 0 max_arg_length = 0 max_desc_length = 0 @plugins.each do |plugin| plugin.name =~ /Deployku::(.*?)Plugin/ next unless $1 name = $1.downcase plugin.help_register.each do |reg| new_reg = { name: "#{name}:#{reg[:name]}", args: reg[:arg_list], desc: reg[:desc] } max_name_length = new_reg[:name].length if new_reg[:name].length > max_name_length max_arg_length = new_reg[:args].length if new_reg[:args].length > max_arg_length max_desc_length = new_reg[:desc].length if new_reg[:desc].length > max_desc_length help_register << new_reg end end help_register.each do |reg| str << " %-#{max_name_length}s %-#{max_arg_length}s %s\n" % [reg[:name], reg[:args], reg[:desc]] end str end |
.inherited(plugin) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/deployku/plugins.rb', line 34 def self.inherited(plugin) Plugin << plugin plugin.instance_eval do @help_register = [] class << self attr_reader :help_register end def describe(fn_name, args, description, acl={}) @help_register << { name: fn_name, arg_list: args, desc: description, acl_app: acl[:acl_app], acl_sys: acl[:acl_sys] } end end end |
.instance ⇒ Object
93 94 95 |
# File 'lib/deployku/plugins.rb', line 93 def self.instance @instance ||= self.new end |
.run(fn, args = []) ⇒ Object
run command in a plugin
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/deployku/plugins.rb', line 73 def self.run(fn, args=[]) fn_name = fn.to_s.gsub(':', '_') fn_desc = command_description(fn) unless fn_desc puts "Unknown command '#{fn}'." exit 1 end if fn_desc[:acl_app] fn_desc[:acl_app].each do |idx, right| Deployku::AccessPlugin.instance.check_app_rights(args[idx], right, true) end end if fn_desc[:acl_sys] Deployku::AccessPlugin.instance.check_system_rights(fn_desc[:acl_sys], true) end plug = instance raise Deployku::Plugin::NoMethod.new("no method '#{plug.class.name}.#{fn}'") unless plug.respond_to?(fn_name) plug.send(fn_name, *args) end |