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.
-
#debug(msg) ⇒ Object
uniform debug logging for plugins.
- #execute ⇒ Object
-
#initialize(runner) ⇒ Plugin
constructor
A new instance of Plugin.
-
#is_configured? ⇒ Boolean
empty plugin configuration.
- #is_enabled? ⇒ Boolean
-
#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.
7 8 9 10 11 |
# File 'lib/lolcommits/plugin.rb', line 7 def initialize(runner) debug "Initializing" self.runner = runner self. = ['enabled'] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/lolcommits/plugin.rb', line 5 def @options end |
#runner ⇒ Object
Returns the value of attribute runner.
5 6 7 |
# File 'lib/lolcommits/plugin.rb', line 5 def runner @runner end |
Class Method Details
.name ⇒ Object
identifying plugin name (for config, listing)
79 80 81 |
# File 'lib/lolcommits/plugin.rb', line 79 def self.name 'plugin' end |
Instance Method Details
#configuration ⇒ Object
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 puts "Configuring plugin: #{self.class.name}\n" .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 |
#execute ⇒ Object
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
62 63 64 |
# File 'lib/lolcommits/plugin.rb', line 62 def is_configured? !configuration.empty? end |
#is_enabled? ⇒ 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 |
#run ⇒ Object
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
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 |