class KnifeSpork::Plugins::Plugin
Public Class Methods
hook(the_hook)
click to toggle source
When defining a hook, we define a method on the instance that corresponds to that hook. That will be fired when the hook is fired.
# File lib/knife-spork/plugins/plugin.rb, line 22 def self.hook(the_hook) self.send(:define_method, the_hook.to_sym) do perform end end
hooks(*the_hooks)
click to toggle source
This is a convenience method for defining multiple hooks in a single call.
# File lib/knife-spork/plugins/plugin.rb, line 16 def self.hooks(*the_hooks) [the_hooks].flatten.each{ |the_hook| hook(the_hook) } end
name(name = nil)
click to toggle source
This is the name of the plugin. It must correspond to the name in the yaml configuration file in order to load this plugin. If an attribute is passed in, the name is set to that given value. Otherwise, the name is returned.
# File lib/knife-spork/plugins/plugin.rb, line 7 def self.name(name = nil) if name.nil? class_variable_get(:@@name) else class_variable_set(:@@name, name) end end
new(options = {})
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 28 def initialize(options = {}) @options = { :payload => {} }.merge(options) end
Public Instance Methods
enabled?()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 34 def enabled? !(config.nil? || config.enabled == false) end
Private Instance Methods
config()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 39 def config @options[:config].plugins.send(self.class.name.to_sym) unless @options[:config].nil? || @options[:config].plugins.nil? end
cookbook_path()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 70 def cookbook_path @options[:cookbook_path] end
cookbooks()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 54 def cookbooks @options[:cookbooks] end
current_user()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 102 def current_user (begin `git config user.name`.chomp; rescue nil; end || ENV['USERNAME'] || ENV['USER']).strip end
environment_diffs()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 62 def environment_diffs @options[:environment_diffs] end
environment_path()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 66 def environment_path @options[:environment_path] end
environments()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 58 def environments @options[:environments] end
misc_output()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 94 def misc_output @options[:misc_output] end
node_path()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 78 def node_path File.expand_path(config.role_path.nil? ? "#{cookbook_path}/../nodes" : config[:role_path]) end
object_difference()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 90 def object_difference @options[:object_difference] end
object_name()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 82 def object_name @options[:object_name] end
object_secondary_name()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 86 def object_secondary_name @options[:object_secondary_name] end
organization()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 43 def organization unless ::Chef::Config.chef_server_url.nil? split_server_url = Chef::Config.chef_server_url.gsub(/http(s)?:\/\//,"").split('/') if split_server_url.length > 1 return "#{split_server_url.last}: " end end nil end
role_path()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 74 def role_path File.expand_path(config.role_path.nil? ? "#{cookbook_path}/../roles" : config[:role_path]) end
safe_require(file)
click to toggle source
Wrapper method around require that attempts to include the associated file. If it does not exist or cannot be loaded, an nice error is produced instead of blowing up.
# File lib/knife-spork/plugins/plugin.rb, line 108 def safe_require(file) begin require file rescue LoadError raise "You are using a plugin for knife-spork that requires #{file}, but you have not installed it. Please either run \"gem install #{file}\", add #{file} to your Gemfile or remove the plugin from your configuration." end end
ui()
click to toggle source
# File lib/knife-spork/plugins/plugin.rb, line 98 def ui @options[:ui] end