Class: Lolcommits::Plugin
- Inherits:
-
Object
- Object
- Lolcommits::Plugin
- Includes:
- Methadone::CLILogging
- Defined in:
- lib/lolcommits/plugin.rb
Direct Known Subclasses
DotCom, LolProtonet, LolSlack, LolTumblr, LolTwitter, LolYammer, Lolsrv, Loltext, Tranzlate, Uploldz
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).
-
.runner_order ⇒ Object
a plugin requests to be run by the runner in one of the possible positions.
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_postcapture ⇒ Object
- #execute_precapture ⇒ Object
-
#initialize(runner) ⇒ Plugin
constructor
A new instance of Plugin.
-
#log_error(e, message) ⇒ Object
helper to log errors with a message via debug.
- #parse_user_input(str) ⇒ Object
-
#puts(*args) ⇒ Object
uniform puts for plugins dont puts if the runner wants to be silent (stealth mode).
- #run_postcapture ⇒ Object
- #run_precapture ⇒ 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)
115 116 117 |
# File 'lib/lolcommits/plugin.rb', line 115 def self.name 'plugin' end |
.runner_order ⇒ Object
a plugin requests to be run by the runner in one of the possible positions. valid options are [:precapture, :postcapture]
121 122 123 |
# File 'lib/lolcommits/plugin.rb', line 121 def self.runner_order nil end |
Instance Method Details
#configuration ⇒ Object
40 41 42 43 44 |
# File 'lib/lolcommits/plugin.rb', line 40 def configuration config = runner.config.read_configuration if runner return {} unless config config[self.class.name] || {} end |
#configure_options! ⇒ Object
ask for plugin options
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lolcommits/plugin.rb', line 47 def puts "Configuring plugin: #{self.class.name}\n" .reduce({}) do |acc, option| print "#{option}: " val = parse_user_input(STDIN.gets.strip) # check enabled option isn't a String if (option == 'enabled') && ![true, false].include?(val) puts "Aborting - please respond with 'true' or 'false'" exit 1 else acc.merge(option => val) end end end |
#configured? ⇒ Boolean
empty plugin configuration
92 93 94 |
# File 'lib/lolcommits/plugin.rb', line 92 def configured? !configuration.empty? end |
#debug(msg) ⇒ Object
uniform debug logging for plugins
110 111 112 |
# File 'lib/lolcommits/plugin.rb', line 110 def debug(msg) super("Plugin: #{self.class}: " + msg) end |
#enabled? ⇒ Boolean
77 78 79 |
# File 'lib/lolcommits/plugin.rb', line 77 def enabled? configuration['enabled'] == true end |
#execute_postcapture ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/lolcommits/plugin.rb', line 23 def execute_postcapture if enabled? debug 'I am enabled, about to run postcapture' run_postcapture else debug 'Disabled, doing nothing for postcapture execution' end end |
#execute_precapture ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/lolcommits/plugin.rb', line 14 def execute_precapture if enabled? debug 'I am enabled, about to run precapture' run_precapture else debug 'Disabled, doing nothing for precapture execution' end end |
#log_error(e, message) ⇒ Object
helper to log errors with a message via debug
104 105 106 107 |
# File 'lib/lolcommits/plugin.rb', line 104 def log_error(e, ) debug debug e.backtrace.join("\n") end |
#parse_user_input(str) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/lolcommits/plugin.rb', line 62 def parse_user_input(str) # cater for bools, strings, ints and blanks if 'true'.casecmp(str) == 0 true elsif 'false'.casecmp(str) == 0 false elsif str =~ /^[0-9]+$/ str.to_i elsif str.strip.empty? nil else str end end |
#puts(*args) ⇒ Object
uniform puts for plugins dont puts if the runner wants to be silent (stealth mode)
98 99 100 101 |
# File 'lib/lolcommits/plugin.rb', line 98 def puts(*args) return if runner && runner.capture_stealth super(args) end |
#run_postcapture ⇒ Object
36 37 38 |
# File 'lib/lolcommits/plugin.rb', line 36 def run_postcapture debug 'base plugin, does nothing to anything' end |
#run_precapture ⇒ Object
32 33 34 |
# File 'lib/lolcommits/plugin.rb', line 32 def run_precapture debug 'base plugin, does nothing to anything' end |
#valid_configuration? ⇒ Boolean
check config is valid
82 83 84 85 86 87 88 89 |
# File 'lib/lolcommits/plugin.rb', line 82 def valid_configuration? if configured? true else puts "Missing #{self.class.name} config - configure with: lolcommits --config -p #{self.class.name}" false end end |