Class: Lolcommits::Plugin

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging
Defined in:
lib/lolcommits/plugin.rb

Direct Known Subclasses

DotCom, LolTwitter, LolYammer, Lolsrv, Loltext, Tranzlate, Uploldz

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ Plugin

Returns a new instance of Plugin.



8
9
10
11
12
# File 'lib/lolcommits/plugin.rb', line 8

def initialize(runner)
  debug 'Initializing'
  self.runner = runner
  self.options = ['enabled']
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/lolcommits/plugin.rb', line 6

def options
  @options
end

#runnerObject

Returns the value of attribute runner.



6
7
8
# File 'lib/lolcommits/plugin.rb', line 6

def runner
  @runner
end

Class Method Details

.nameObject

identifying plugin name (for config, listing)



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

def self.name
  'plugin'
end

Instance Method Details

#configurationObject



27
28
29
30
31
# File 'lib/lolcommits/plugin.rb', line 27

def configuration
  config = runner.config.read_configuration if runner
  return {} unless config
  config[self.class.name] || {}
end

#configure_options!Object

ask for plugin options



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lolcommits/plugin.rb', line 34

def configure_options!
  puts "Configuring plugin: #{self.class.name}\n"
  options.reduce(Hash.new) do |acc, option|
    print "#{option}: "
    val = STDIN.gets.strip.downcase
    if %w(true yes).include?(val)
      val = true
    elsif %(false no).include?(val)
      val = false
    end
    acc.merge(option => val)
  end
end

#configured?Boolean

empty plugin configuration

Returns:

  • (Boolean)


63
64
65
# File 'lib/lolcommits/plugin.rb', line 63

def configured?
  !configuration.empty?
end

#debug(msg) ⇒ Object

uniform debug logging for plugins



75
76
77
# File 'lib/lolcommits/plugin.rb', line 75

def debug(msg)
  super("Plugin: #{self.class.to_s}: " + msg)
end

#enabled?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/lolcommits/plugin.rb', line 48

def enabled?
  configuration['enabled'] == true
end

#executeObject



14
15
16
17
18
19
20
21
# File 'lib/lolcommits/plugin.rb', line 14

def execute
  if enabled?
    debug 'I am enabled, about to run'
    run
  else
    debug 'Disabled, doing nothing for execution'
  end
end

#puts(*args) ⇒ Object

uniform puts for plugins dont puts if the runner wants to be silent (stealth mode)



69
70
71
72
# File 'lib/lolcommits/plugin.rb', line 69

def puts(*args)
  return if runner && runner.capture_stealth
  super(args)
end

#runObject



23
24
25
# File 'lib/lolcommits/plugin.rb', line 23

def run
  debug 'base plugin, does nothing to anything'
end

#valid_configuration?Boolean

check config is valid

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
# File 'lib/lolcommits/plugin.rb', line 53

def valid_configuration?
  if configured?
    true
  else
    puts "Missing #{self.class.name} config - configure with: lolcommits --config -p #{self.class.name}"
    false
  end
end