Class: Lolcommits::Plugin
- Inherits:
-
Object
- Object
- Lolcommits::Plugin
- Includes:
- Methadone::CLILogging
- Defined in:
- lib/lolcommits/plugin.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#runner ⇒ Object
Returns the value of attribute runner.
Class Method Summary collapse
-
.name ⇒ Object
identifying plugin name (for config, listing).
Instance Method Summary collapse
- #configuration ⇒ Object
-
#configure_options! ⇒ Object
ask for plugin options.
-
#configured? ⇒ Boolean
empty plugin configuration.
-
#debug(msg) ⇒ Object
uniform debug logging for plugins.
- #enabled? ⇒ Boolean
- #execute ⇒ Object
-
#initialize(runner) ⇒ Plugin
constructor
A new instance of Plugin.
-
#puts(*args) ⇒ Object
uniform puts for plugins dont puts if the runner wants to be silent (stealth mode).
- #run ⇒ Object
-
#valid_configuration? ⇒ Boolean
check config is valid.
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. = ['enabled'] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/lolcommits/plugin.rb', line 6 def @options end |
#runner ⇒ Object
Returns the value of attribute runner.
6 7 8 |
# File 'lib/lolcommits/plugin.rb', line 6 def runner @runner end |
Class Method Details
.name ⇒ Object
identifying plugin name (for config, listing)
80 81 82 |
# File 'lib/lolcommits/plugin.rb', line 80 def self.name 'plugin' end |
Instance Method Details
#configuration ⇒ Object
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 puts "Configuring plugin: #{self.class.name}\n" .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
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
48 49 50 |
# File 'lib/lolcommits/plugin.rb', line 48 def enabled? configuration['enabled'] == true end |
#execute ⇒ Object
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 |
#run ⇒ Object
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
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 |