Class: Lolcommits::Plugin::Base
- Inherits:
-
Object
- Object
- Lolcommits::Plugin::Base
- Defined in:
- lib/lolcommits/plugin/base.rb
Direct Known Subclasses
DotCom, LolFlowdock, LolHipchat, LolProtonet, LolSlack, LolTumblr, LolTwitter, LolYammer, Lolsrv, Loltext, TermOutput, 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 ⇒ 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.
-
#debug(msg) ⇒ Object
uniform debug logging for plugins.
- #enabled? ⇒ Boolean
- #execute_postcapture ⇒ Object
- #execute_precapture ⇒ Object
-
#initialize(runner) ⇒ 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
-
#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) ⇒ Base
Returns a new instance of Base.
6 7 8 9 |
# File 'lib/lolcommits/plugin/base.rb', line 6 def initialize(runner) self.runner = runner self. = ['enabled'] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/lolcommits/plugin/base.rb', line 4 def @options 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)
99 100 101 |
# File 'lib/lolcommits/plugin/base.rb', line 99 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.
111 112 113 |
# File 'lib/lolcommits/plugin/base.rb', line 111 def self.runner_order [] end |
Instance Method Details
#configuration ⇒ Object
29 30 31 32 33 |
# File 'lib/lolcommits/plugin/base.rb', line 29 def configuration config = runner.config.read_configuration if runner return {} unless config config[self.class.name] || {} end |
#configure_options! ⇒ Object
ask for plugin options
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lolcommits/plugin/base.rb', line 36 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
76 77 78 |
# File 'lib/lolcommits/plugin/base.rb', line 76 def configured? !configuration.empty? end |
#debug(msg) ⇒ Object
uniform debug logging for plugins
94 95 96 |
# File 'lib/lolcommits/plugin/base.rb', line 94 def debug(msg) super("#{self.class}: " + msg) end |
#enabled? ⇒ Boolean
66 67 68 |
# File 'lib/lolcommits/plugin/base.rb', line 66 def enabled? configuration['enabled'] == true end |
#execute_postcapture ⇒ Object
18 19 20 21 22 23 |
# File 'lib/lolcommits/plugin/base.rb', line 18 def execute_postcapture return unless valid_configuration? return unless enabled? debug 'I am enabled, about to run postcapture' run_postcapture end |
#execute_precapture ⇒ Object
11 12 13 14 15 16 |
# File 'lib/lolcommits/plugin/base.rb', line 11 def execute_precapture return unless valid_configuration? return unless enabled? debug 'I am enabled, about to run precapture' run_precapture end |
#log_error(e, message) ⇒ Object
helper to log errors with a message via debug
88 89 90 91 |
# File 'lib/lolcommits/plugin/base.rb', line 88 def log_error(e, ) debug debug e.backtrace.join("\n") end |
#parse_user_input(str) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/lolcommits/plugin/base.rb', line 51 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 |
#puts(*args) ⇒ Object
uniform puts for plugins dont puts if the runner wants to be silent (stealth mode)
82 83 84 85 |
# File 'lib/lolcommits/plugin/base.rb', line 82 def puts(*args) return if runner && runner.capture_stealth super(args) end |
#run_postcapture ⇒ Object
27 |
# File 'lib/lolcommits/plugin/base.rb', line 27 def run_postcapture; end |
#run_precapture ⇒ Object
25 |
# File 'lib/lolcommits/plugin/base.rb', line 25 def run_precapture; end |
#valid_configuration? ⇒ Boolean
check config is valid
71 72 73 |
# File 'lib/lolcommits/plugin/base.rb', line 71 def valid_configuration? configured? end |