Class: Lolcommits::Plugin::Sample

Inherits:
Base
  • Object
show all
Defined in:
lib/lolcommits/plugin/sample.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ Sample

Plugin initializer

The default superclass method sets the @runner instance var and default plugin option keys e.g. @options = ['enabled']

Override this method to change the default options, or assign any useful variables necessary for the plugin to run.

Parameters:

  • runner (Lolcommits::Runner)

    a instance of a lolcommits runner



42
43
44
# File 'lib/lolcommits/plugin/sample.rb', line 42

def initialize(runner)
  super
end

Class Method Details

.nameString

Returns the name of the plugin.

Identifies the plugin to lolcommits. This should be uniq and descriptive.

Returns:

  • (String)

    the plugin name



15
16
17
# File 'lib/lolcommits/plugin/sample.rb', line 15

def self.name
  'plugin-sample'
end

.runner_orderArray

Returns position(s) of when this plugin should run during the capture process.

Defines when your plugin will execute in the capture process. This must be defined, if the method returns nil, or [] the plugin will never run.

Returns:

  • (Array)

    the position(s) (:precapture and/or :postcapture)



27
28
29
# File 'lib/lolcommits/plugin/sample.rb', line 27

def self.runner_order
  [:precapture, :postcapture]
end

Instance Method Details

#configure_options!Hash

Prompts the user to configure the plugin's options.

The default superclass method will iterate over the @options array and build a configuration hash, prompting for user input on each option key.

Lolcommits will save this configuration hash to its default config file (YAML). This config Hash is loaded and parsed during the capturing process and available in this plugin class via the configuration method.

Override this method to define your own configuration flow. A helpful parse_user_input method is available to help parse strings from STDIN.

Returns:

  • (Hash)

    a hash of configured plugin options



105
106
107
# File 'lib/lolcommits/plugin/sample.rb', line 105

def configure_options!
  super
end

#configured?Boolean

Returns true/false indicating if the plugin has been configured.

The default superclass method checks if the configuration hash is empty. Override this method to define your own check on whether configuration has taken place.

Returns:

  • (Boolean)

    true/false indicating if plugin has been configured



138
139
140
# File 'lib/lolcommits/plugin/sample.rb', line 138

def configured?
  super
end

#enabled?Boolean

Returns true/false indicating if the plugin is enabled or not.

The default superclass method will return true if the enabled option is true e.g. configuration == true

Override this method to define your own custom enabled logic. E.g. check for valid or required configuration options to be set. If this method always returns true, the only way to disable the plugin will be to uninstall the gem.

Returns:

  • (Boolean)

    true/false indicating if plugin is enabled



86
87
88
# File 'lib/lolcommits/plugin/sample.rb', line 86

def enabled?
  super
end

#run_postcaptureObject

Post-capture hook, runs after lolcommits captures a snapshot.

Override this method to execute plugin code after the lolcommit snapshot is captured.

Prints a short (emoji themed) message to STDOUT with the current commit sha.



69
70
71
# File 'lib/lolcommits/plugin/sample.rb', line 69

def run_postcapture
  puts "✨  wow! #{self.runner.sha} is your best looking commit yet! 😘  💻"
end

#run_precaptureObject

Pre-capture hook, runs before lolcommits captures a snapshot.

Override this method to execute plugin code before the lolcommit snapshot is captured.

Prints a short (emoji themed) message to STDOUT



55
56
57
# File 'lib/lolcommits/plugin/sample.rb', line 55

def run_precapture
  puts "✨  Say cheese 😁 !"
end

#valid_configuration?Boolean

Returns true/false indicating if the plugin has been correctly configured.

The default superclass method calls configured?. When false a message is shown explaining the plugin has not yet been configured, with help on how to configure it.

Override this method to define your own configuration checks and messaging.

This method must return true for the plugin to execute. It is checked by the lolcommits runner prior to running a pre or post capture hook.

Returns:

  • (Boolean)

    true/false indicating if plugin is correct configured



125
126
127
# File 'lib/lolcommits/plugin/sample.rb', line 125

def valid_configuration?
  super
end