Class: KnifeSpork::Plugins::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/knife-spork/plugins/plugin.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Plugin

Returns a new instance of Plugin.



28
29
30
31
32
# File 'lib/knife-spork/plugins/plugin.rb', line 28

def initialize(options = {})
  @options = {
    :payload => {}
  }.merge(options)
end

Class Method Details

.hook(the_hook) ⇒ Object

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.



22
23
24
25
26
# 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) ⇒ Object

This is a convenience method for defining multiple hooks in a single call.



16
17
18
# 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) ⇒ Object

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.



7
8
9
10
11
12
13
# 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

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/knife-spork/plugins/plugin.rb', line 34

def enabled?
  !(config.nil? || config.enabled == false)
end