lolcommits-sample_plugin 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +5 -4
- data/lib/lolcommits/plugin/sample_plugin.rb +67 -64
- data/lib/lolcommits/sample_plugin/version.rb +1 -1
- data/lolcommits-plugin-sample.gemspec +1 -1
- data/test/lolcommits/plugin/sample_plugin_test.rb +14 -29
- data/test/test_helper.rb +1 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 458f611a07c9da71c65f2158fa4d3c28882c9c9955666e08ae3ad3f80ca9eceb
|
4
|
+
data.tar.gz: 11ef71f56de73bc96d06f0e24fd0d20e2fe731c15ef23a6da495db50f15cfa9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ede2aeb0f2b4d3ac198b0d0ed3d9ab39e9df9e4fd9a213df9fd0ea7900fcf43714a906fda0e83d66ab785fc918f9d8ea867ba941e895c22915460f27836cc9a
|
7
|
+
data.tar.gz: c5103c9f2e1272427d3e04a58c0fc74e2511d1703501063c62c5c43d850be66fb4b51e9970dd88519ca6d5b11e7575b00759708fecaa2f981c8e2e0bf086dc26
|
data/.travis.yml
CHANGED
@@ -4,13 +4,14 @@ cache: bundler
|
|
4
4
|
rvm:
|
5
5
|
- 2.0.0
|
6
6
|
- 2.1.10
|
7
|
-
- 2.2.
|
8
|
-
- 2.3.
|
9
|
-
- 2.4.
|
7
|
+
- 2.2.9
|
8
|
+
- 2.3.6
|
9
|
+
- 2.4.3
|
10
|
+
- 2.5.0
|
10
11
|
- ruby-head
|
11
12
|
|
12
13
|
before_install:
|
13
|
-
- gem
|
14
|
+
- gem update --system
|
14
15
|
- git --version
|
15
16
|
- git config --global user.email "lol@commits.org"
|
16
17
|
- git config --global user.name "Lolcommits"
|
@@ -5,17 +5,21 @@ module Lolcommits
|
|
5
5
|
class SamplePlugin < Base
|
6
6
|
|
7
7
|
##
|
8
|
-
#
|
8
|
+
# Plugin initializer
|
9
|
+
#
|
10
|
+
# @param runner [Lolcommits::Runner] an instance of a lolcommits runner
|
11
|
+
# @param config [Hash] plugin config hash (parsed from saved config YAML)
|
9
12
|
#
|
10
|
-
#
|
11
|
-
#
|
13
|
+
# The default superclass method sets @runner and @configuration instance
|
14
|
+
# vars and @options to `[:enabled]`
|
12
15
|
#
|
13
|
-
#
|
16
|
+
# Override this method to change the default configurable option names
|
14
17
|
#
|
15
|
-
def
|
16
|
-
|
18
|
+
def initialize(runner: nil, config: nil)
|
19
|
+
super
|
17
20
|
end
|
18
21
|
|
22
|
+
##
|
19
23
|
# Returns position(s) of when this plugin should run during the capture
|
20
24
|
# process.
|
21
25
|
#
|
@@ -31,24 +35,6 @@ module Lolcommits
|
|
31
35
|
[:pre_capture, :post_capture, :capture_ready]
|
32
36
|
end
|
33
37
|
|
34
|
-
##
|
35
|
-
#
|
36
|
-
# Plugin initializer
|
37
|
-
#
|
38
|
-
# @param runner [Lolcommits::Runner] a instance of a lolcommits runner
|
39
|
-
# @param config [Lolcommits::Configuration] (optional)
|
40
|
-
#
|
41
|
-
# The default superclass method sets @runner and @config instance vars and
|
42
|
-
# the default plugin option key `@options = ['enabled']`. `@runner.config`
|
43
|
-
# is used if no `config` parameter is passed.
|
44
|
-
#
|
45
|
-
# Override this method to change the default options, or assign any useful
|
46
|
-
# variables necessary for the plugin to run.
|
47
|
-
#
|
48
|
-
def initialize(runner: nil, config: nil)
|
49
|
-
super
|
50
|
-
end
|
51
|
-
|
52
38
|
##
|
53
39
|
#
|
54
40
|
# Pre-capture hook, runs before lolcommits captures a snapshot.
|
@@ -59,20 +45,21 @@ module Lolcommits
|
|
59
45
|
# Prints a short (emoji themed) message to STDOUT
|
60
46
|
#
|
61
47
|
def run_pre_capture
|
62
|
-
puts "✨ Say cheese 😁 !"
|
48
|
+
puts "✨ Say cheese 😁 !" if config_option(:ask_for_cheese)
|
63
49
|
end
|
64
50
|
|
65
51
|
##
|
66
52
|
#
|
67
53
|
# Post-capture hook, run after lolcommits captures a snapshot.
|
68
54
|
#
|
69
|
-
# Override this method to execute plugin code after the lolcommit
|
70
|
-
#
|
55
|
+
# Override this method to execute plugin code after the lolcommit snapshot
|
56
|
+
# is captured.
|
71
57
|
#
|
72
58
|
# Prints a short (emoji themed) message to STDOUT
|
73
59
|
#
|
74
60
|
def run_post_capture
|
75
|
-
|
61
|
+
return unless config_option(:camera_emoji, :enabled)
|
62
|
+
puts "#{"📸 " * config_option(:camera_emoji, :emoji_multiplier).to_i}Snap!"
|
76
63
|
end
|
77
64
|
|
78
65
|
##
|
@@ -87,19 +74,24 @@ module Lolcommits
|
|
87
74
|
# sha.
|
88
75
|
#
|
89
76
|
def run_capture_ready
|
90
|
-
|
77
|
+
if config_option(:always_a_great_commit?)
|
78
|
+
puts "✨ wow! #{self.runner.sha} is your best looking commit yet! 😘 💻"
|
79
|
+
end
|
91
80
|
end
|
92
81
|
|
93
82
|
##
|
94
83
|
# Returns true/false indicating if the plugin is enabled or not.
|
95
84
|
#
|
96
|
-
# The default superclass method
|
97
|
-
#
|
85
|
+
# The default superclass method returns true if the enabled option is true
|
86
|
+
# i.e. configuration[:enabled] == true
|
98
87
|
#
|
99
|
-
# Override this method to define your own custom enabled logic.
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
88
|
+
# Override this method to define your own custom enabled logic. If this
|
89
|
+
# method always returns true, the only way to disable the plugin will be
|
90
|
+
# to uninstall the gem.
|
91
|
+
#
|
92
|
+
# Note: a `valid_configuration?` method also exists and is checked before
|
93
|
+
# any plugin hooks execute. Use that to check individual config option
|
94
|
+
# values.
|
103
95
|
#
|
104
96
|
# @return [Boolean] true/false indicating if plugin is enabled
|
105
97
|
#
|
@@ -108,56 +100,67 @@ module Lolcommits
|
|
108
100
|
end
|
109
101
|
|
110
102
|
##
|
111
|
-
# Prompts the user to configure
|
103
|
+
# Prompts the user to configure all plugin options.
|
104
|
+
#
|
105
|
+
# Available options can be defined in an Array (@options instance var)
|
106
|
+
# and/or a Hash (by overriding the `default_options` method).
|
112
107
|
#
|
113
|
-
#
|
114
|
-
#
|
108
|
+
# By default (on initialize), `@options` is set with `[:enabled]`. This is
|
109
|
+
# mandatory since `enabled?` checks this option is true before running any
|
110
|
+
# capture hooks.
|
115
111
|
#
|
116
|
-
#
|
117
|
-
# (YAML). This config Hash is loaded and parsed during the capturing
|
118
|
-
# process and available in this plugin class via the configuration method.
|
112
|
+
# Using a Hash to define default options allows you to:
|
119
113
|
#
|
120
|
-
#
|
121
|
-
#
|
114
|
+
# - fall back to default values
|
115
|
+
# - define nested options, user is prompted for each nested option key
|
122
116
|
#
|
123
|
-
#
|
117
|
+
# `configure_option_hash` will iterate over all options prompting the user
|
118
|
+
# for input and building the configuration Hash.
|
119
|
+
#
|
120
|
+
# Lolcommits will save this Hash to a YAML file. During the capture
|
121
|
+
# process the configuration is loaded, parsed and available in the plugin
|
122
|
+
# class as `@configuration`. Or if you want to fall back to default
|
123
|
+
# values, you should use `config_option` to dig the hash.
|
124
|
+
#
|
125
|
+
# Alternatively you can override this method entirely to customise the
|
126
|
+
# process. A helpful `parse_user_input` method is available to help parse
|
127
|
+
# strings from STDIN (into boolean, integer or nil values).
|
128
|
+
#
|
129
|
+
# @return [Hash] the configured plugin options
|
124
130
|
#
|
125
131
|
def configure_options!
|
126
132
|
super
|
127
133
|
end
|
128
134
|
|
135
|
+
def default_options
|
136
|
+
{
|
137
|
+
ask_for_cheese: true,
|
138
|
+
always_a_great_commit?: true,
|
139
|
+
camera_emoji: {
|
140
|
+
enabled: false,
|
141
|
+
emoji_multiplier: 2
|
142
|
+
}
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
129
146
|
##
|
130
147
|
# Returns true/false indicating if the plugin has been correctly
|
131
148
|
# configured.
|
132
149
|
#
|
133
|
-
# The default superclass method
|
134
|
-
#
|
135
|
-
# how to configure it.
|
150
|
+
# The default superclass method simply checks if `@configuration` is
|
151
|
+
# present (not empty).
|
136
152
|
#
|
137
|
-
#
|
138
|
-
#
|
153
|
+
# By default if this method returns false, plugin hooks will not execute
|
154
|
+
# and a warning message is shown prompting the user to re-configure the
|
155
|
+
# plugin.
|
139
156
|
#
|
140
|
-
#
|
141
|
-
# the lolcommits runner prior to running a pre or post capture hook.
|
157
|
+
# Override to define your own configuration checks and/or messaging.
|
142
158
|
#
|
143
159
|
# @return [Boolean] true/false indicating if plugin is correct configured
|
144
160
|
#
|
145
161
|
def valid_configuration?
|
146
162
|
super
|
147
163
|
end
|
148
|
-
|
149
|
-
##
|
150
|
-
# Returns true/false indicating if the plugin has been configured.
|
151
|
-
#
|
152
|
-
# The default superclass method checks if the configuration hash is empty.
|
153
|
-
# Override this method to define your own check on whether configuration
|
154
|
-
# has taken place.
|
155
|
-
#
|
156
|
-
# @return [Boolean] true/false indicating if plugin has been configured
|
157
|
-
#
|
158
|
-
def configured?
|
159
|
-
super
|
160
|
-
end
|
161
164
|
end
|
162
165
|
end
|
163
166
|
end
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.required_ruby_version = ">= 2.0.0"
|
34
34
|
|
35
|
-
spec.add_development_dependency "lolcommits", ">= 0.
|
35
|
+
spec.add_development_dependency "lolcommits", ">= 0.10.0"
|
36
36
|
spec.add_development_dependency "bundler"
|
37
37
|
spec.add_development_dependency "rake"
|
38
38
|
spec.add_development_dependency "minitest"
|
@@ -14,9 +14,7 @@ describe Lolcommits::Plugin::SamplePlugin do
|
|
14
14
|
describe 'with a runner' do
|
15
15
|
def runner
|
16
16
|
# a simple lolcommits runner with an empty configuration Hash
|
17
|
-
@runner ||= Lolcommits::Runner.new
|
18
|
-
config: OpenStruct.new(read_configuration: {})
|
19
|
-
)
|
17
|
+
@runner ||= Lolcommits::Runner.new
|
20
18
|
end
|
21
19
|
|
22
20
|
def plugin
|
@@ -24,22 +22,18 @@ describe Lolcommits::Plugin::SamplePlugin do
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def valid_enabled_config
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
{
|
26
|
+
enabled: true,
|
27
|
+
ask_for_cheese: false,
|
28
|
+
always_a_great_commit?: true,
|
29
|
+
camera_emoji: {
|
30
|
+
enabled: true,
|
31
|
+
emoji_multiplier: 5
|
30
32
|
}
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'initalizing' do
|
35
|
-
it 'should assign runner and an enabled option' do
|
36
|
-
plugin.runner.must_equal runner
|
37
|
-
plugin.options.must_equal ['enabled']
|
38
|
-
end
|
33
|
+
}
|
39
34
|
end
|
40
35
|
|
41
36
|
describe '#run_pre_capture' do
|
42
|
-
|
43
37
|
before { commit_repo_with_message }
|
44
38
|
|
45
39
|
it 'should output a message to stdout' do
|
@@ -68,33 +62,24 @@ describe Lolcommits::Plugin::SamplePlugin do
|
|
68
62
|
|
69
63
|
describe '#enabled?' do
|
70
64
|
it 'should be false by default' do
|
71
|
-
plugin.enabled
|
65
|
+
assert_nil plugin.enabled?
|
72
66
|
end
|
73
67
|
|
74
68
|
it 'should true when configured' do
|
75
|
-
plugin.
|
69
|
+
plugin.configuration = valid_enabled_config
|
76
70
|
plugin.enabled?.must_equal true
|
77
71
|
end
|
78
72
|
end
|
79
73
|
|
80
74
|
describe 'configuration' do
|
81
|
-
it 'should not be configured by default' do
|
82
|
-
plugin.configured?.must_equal false
|
83
|
-
end
|
84
|
-
|
85
75
|
it 'should allow plugin options to be configured' do
|
86
76
|
configured_plugin_options = {}
|
87
77
|
|
88
|
-
output = fake_io_capture(inputs: %w(true)) do
|
78
|
+
output = fake_io_capture(inputs: %w(true false true true 5)) do
|
89
79
|
configured_plugin_options = plugin.configure_options!
|
90
80
|
end
|
91
81
|
|
92
|
-
configured_plugin_options.must_equal(
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should indicate when configured' do
|
96
|
-
plugin.config = valid_enabled_config
|
97
|
-
plugin.configured?.must_equal true
|
82
|
+
configured_plugin_options.must_equal(valid_enabled_config)
|
98
83
|
end
|
99
84
|
|
100
85
|
describe '#valid_configuration?' do
|
@@ -103,7 +88,7 @@ describe Lolcommits::Plugin::SamplePlugin do
|
|
103
88
|
end
|
104
89
|
|
105
90
|
it 'should be true for a valid configuration' do
|
106
|
-
plugin.
|
91
|
+
plugin.configuration = valid_enabled_config
|
107
92
|
plugin.valid_configuration?.must_equal true
|
108
93
|
end
|
109
94
|
end
|
data/test/test_helper.rb
CHANGED
@@ -2,9 +2,7 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
2
|
|
3
3
|
# necessary libs from lolcommits (allowing plugin to run)
|
4
4
|
require 'git'
|
5
|
-
require 'lolcommits
|
6
|
-
require 'lolcommits/vcs_info'
|
7
|
-
require 'lolcommits/backends/git_info'
|
5
|
+
require 'lolcommits'
|
8
6
|
|
9
7
|
# lolcommit test helpers
|
10
8
|
require 'lolcommits/test_helpers/git_repo'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolcommits-sample_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Hutchinson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lolcommits
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.10.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.10.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.7.3
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Example gem for lolcommits plugin development
|