Class: Lolcommits::Plugin

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

Direct Known Subclasses

DotCom, LolTwitter, 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.



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

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#runnerObject

Returns the value of attribute runner.



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

def runner
  @runner
end

Class Method Details

.nameObject

identifying plugin name (for config, listing)



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

def self.name
  'plugin'
end

Instance Method Details

#configurationObject



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

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

#configure_options!Object

ask for plugin options



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

def configure_options!
  puts "Configuring plugin: #{self.class.name}\n"
  options.inject(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

#debug(msg) ⇒ Object

uniform debug logging for plugins



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

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

#executeObject



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

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

#is_configured?Boolean

empty plugin configuration

Returns:

  • (Boolean)


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

def is_configured?
  !configuration.empty?
end

#is_enabled?Boolean

Returns:

  • (Boolean)


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

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

#puts(*args) ⇒ Object

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



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

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

#runObject



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

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

#valid_configuration?Boolean

check config is valid

Returns:

  • (Boolean)


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

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