Class: Lolcommits::Plugin::Base
- Inherits:
-
Object
- Object
- Lolcommits::Plugin::Base
- Defined in:
- lib/lolcommits/plugin/base.rb
Direct Known Subclasses
LolFlowdock, LolHipchat, LolProtonet, LolTumblr, LolYammer, TermOutput
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#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 ⇒ Array
Returns position(s) of when a plugin should run during the capture process.
Instance Method Summary collapse
- #configuration ⇒ Object
-
#configure_options! ⇒ Object
ask for plugin options.
-
#configured? ⇒ Boolean
empty plugin configuration.
- #configured_and_enabled? ⇒ Boolean
-
#debug(msg) ⇒ Object
uniform debug logging for plugins.
- #enabled? ⇒ Boolean
- #execute_capture_ready ⇒ Object
- #execute_post_capture ⇒ Object
- #execute_pre_capture ⇒ Object
-
#initialize(runner: nil, config: nil) ⇒ Base
constructor
A new instance of Base.
-
#log_error(e, message) ⇒ Object
helper to log errors with a message via debug.
- #parse_user_input(str) ⇒ Object
- #print(args) ⇒ Object
-
#puts(*args) ⇒ Object
uniform puts and print for plugins dont puts or print if the runner wants to be silent (stealth mode).
- #run_capture_ready ⇒ Object
- #run_post_capture ⇒ Object
- #run_pre_capture ⇒ Object
-
#valid_configuration? ⇒ Boolean
check config is valid.
Constructor Details
#initialize(runner: nil, config: nil) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 |
# File 'lib/lolcommits/plugin/base.rb', line 6 def initialize(runner: nil, config: nil) self.runner = runner self.config = config || runner.config self. = ['enabled'] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/lolcommits/plugin/base.rb', line 4 def config @config end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/lolcommits/plugin/base.rb', line 4 def end |
#runner ⇒ Object
Returns the value of attribute runner.
4 5 6 |
# File 'lib/lolcommits/plugin/base.rb', line 4 def runner @runner end |
Class Method Details
.name ⇒ Object
identifying plugin name (for config, listing)
115 116 117 |
# File 'lib/lolcommits/plugin/base.rb', line 115 def self.name 'plugin' end |
.runner_order ⇒ Array
Returns position(s) of when a plugin should run during the capture process.
Defines when the plugin will execute in the capture process. This must be defined, if the method returns nil, or [] the plugin will never run. Three hook positions exist, your plugin code can execute in one or more of these.
:capture_ready)
130 131 132 |
# File 'lib/lolcommits/plugin/base.rb', line 130 def self.runner_order [] end |
Instance Method Details
#configuration ⇒ Object
36 37 38 39 40 |
# File 'lib/lolcommits/plugin/base.rb', line 36 def configuration saved_config = config.read_configuration return {} unless saved_config saved_config[self.class.name] || {} end |
#configure_options! ⇒ Object
ask for plugin options
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lolcommits/plugin/base.rb', line 43 def puts "Configuring plugin: #{self.class.name}\n" .reduce({}) do |acc, option| print "#{option}: " val = parse_user_input(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
87 88 89 |
# File 'lib/lolcommits/plugin/base.rb', line 87 def configured? !configuration.empty? end |
#configured_and_enabled? ⇒ Boolean
73 74 75 |
# File 'lib/lolcommits/plugin/base.rb', line 73 def configured_and_enabled? valid_configuration? && enabled? end |
#debug(msg) ⇒ Object
uniform debug logging for plugins
110 111 112 |
# File 'lib/lolcommits/plugin/base.rb', line 110 def debug(msg) super("#{self.class}: " + msg) end |
#enabled? ⇒ Boolean
77 78 79 |
# File 'lib/lolcommits/plugin/base.rb', line 77 def enabled? configuration['enabled'] == true end |
#execute_capture_ready ⇒ Object
24 25 26 27 28 |
# File 'lib/lolcommits/plugin/base.rb', line 24 def execute_capture_ready return unless configured_and_enabled? debug 'I am enabled, about to run capture ready' run_capture_ready end |
#execute_post_capture ⇒ Object
18 19 20 21 22 |
# File 'lib/lolcommits/plugin/base.rb', line 18 def execute_post_capture return unless configured_and_enabled? debug 'I am enabled, about to run post capture' run_post_capture end |
#execute_pre_capture ⇒ Object
12 13 14 15 16 |
# File 'lib/lolcommits/plugin/base.rb', line 12 def execute_pre_capture return unless configured_and_enabled? debug 'I am enabled, about to run pre capture' run_pre_capture end |
#log_error(e, message) ⇒ Object
helper to log errors with a message via debug
104 105 106 107 |
# File 'lib/lolcommits/plugin/base.rb', line 104 def log_error(e, ) debug debug e.backtrace.join("\n") end |
#parse_user_input(str) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lolcommits/plugin/base.rb', line 58 def parse_user_input(str) # cater for bools, strings, ints and blanks if 'true'.casecmp(str).zero? true elsif 'false'.casecmp(str).zero? false elsif str =~ /^[0-9]+$/ str.to_i elsif str.strip.empty? nil else str end end |
#print(args) ⇒ Object
98 99 100 101 |
# File 'lib/lolcommits/plugin/base.rb', line 98 def print(args) return if runner && runner.capture_stealth super(args) end |
#puts(*args) ⇒ Object
uniform puts and print for plugins dont puts or print if the runner wants to be silent (stealth mode)
93 94 95 96 |
# File 'lib/lolcommits/plugin/base.rb', line 93 def puts(*args) return if runner && runner.capture_stealth super(args) end |
#run_capture_ready ⇒ Object
34 |
# File 'lib/lolcommits/plugin/base.rb', line 34 def run_capture_ready; end |
#run_post_capture ⇒ Object
32 |
# File 'lib/lolcommits/plugin/base.rb', line 32 def run_post_capture; end |
#run_pre_capture ⇒ Object
30 |
# File 'lib/lolcommits/plugin/base.rb', line 30 def run_pre_capture; end |
#valid_configuration? ⇒ Boolean
check config is valid
82 83 84 |
# File 'lib/lolcommits/plugin/base.rb', line 82 def valid_configuration? configured? end |