retrospec 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/retrospec.rb +0 -1
- data/lib/retrospec/cli.rb +7 -5
- data/lib/retrospec/plugins/v1/module_helpers.rb +9 -0
- data/lib/retrospec/plugins/v1/plugin.rb +2 -3
- data/lib/version.rb +1 -1
- data/plugin_development.md +45 -9
- data/retrospec.gemspec +2 -3
- data/spec/retrospec_spec.rb +0 -3
- metadata +2 -3
- data/lib/retrospec/module.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6babe7c886b994aea6dc72564d79fef92170cc78
|
4
|
+
data.tar.gz: 8667464aba52550fa565d43f6f7ca5ba3974703d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c0ce0d81d0f96193a0b9ae5d1785fde481e69e0c204ca2532a265d812245499ce140d91a068e46028cd2c4d88686d9ee50a108f7b302f532051ff7fa7187643
|
7
|
+
data.tar.gz: cec45e06072d9a46ce300528c2b535eea917fd06f12e755fbbf7ac9c109b2b3af9ccd13d849c51621c4a3c879c37e5b6f48753c0867eedf1d8374b1a3e03a466
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/retrospec.rb
CHANGED
data/lib/retrospec/cli.rb
CHANGED
@@ -9,6 +9,7 @@ module Retrospec
|
|
9
9
|
|
10
10
|
def self.run
|
11
11
|
cli = Retrospec::Cli.new
|
12
|
+
# get the list of plugins and provide the plugin name as sub commands
|
12
13
|
sub_commands = cli.plugin_map.keys
|
13
14
|
cmd_help = sub_commands.join("\n")
|
14
15
|
|
@@ -30,11 +31,12 @@ Available subcommands:
|
|
30
31
|
end
|
31
32
|
cmd = ARGV.shift # get the subcommand
|
32
33
|
if plugin_class = cli.plugin_map[cmd]
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Retrospec::
|
34
|
+
# this is what generates the cli options for the subcommand
|
35
|
+
# this is also the main entry point that runs the plugin's cli
|
36
|
+
global_config = Retrospec::Config.config_data(global_opts[:config_map])
|
37
|
+
plugin_name = plugin_class.send(:plugin_name)
|
38
|
+
plugin_config = Retrospec::Config.plugin_context(global_config, plugin_name)
|
39
|
+
plugin_class.send(:run_cli, global_opts, global_config, plugin_config)
|
38
40
|
else
|
39
41
|
if global_opts[:available_plugins]
|
40
42
|
Retrospec::Cli.list_available_plugins
|
@@ -18,6 +18,15 @@ module Retrospec
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def safe_move_file(src,dest)
|
22
|
+
if File.exists?(dest)
|
23
|
+
$stderr.puts "!! #{dest} already exists and differs from template".warning
|
24
|
+
else
|
25
|
+
FileUtils.mv(src,dest)
|
26
|
+
puts " + #{dest}".info
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
21
30
|
# copy the symlink and preserve the link
|
22
31
|
def safe_create_symlink(src,dest)
|
23
32
|
if File.exists? dest
|
@@ -39,9 +39,8 @@ module Retrospec
|
|
39
39
|
|
40
40
|
# used to display subcommand options to the cli
|
41
41
|
# the global options are passed in for your usage
|
42
|
-
def self.
|
43
|
-
|
44
|
-
end
|
42
|
+
def self.run_cli(global_opts, global_config, plugin_config)
|
43
|
+
raise NotImplemented
|
45
44
|
end
|
46
45
|
|
47
46
|
# the name of the plugin that will be sent to the cli
|
data/lib/version.rb
CHANGED
data/plugin_development.md
CHANGED
@@ -13,30 +13,66 @@ create a retrospec plugin. Follow the steps below to create a plugin.
|
|
13
13
|
|
14
14
|
## Choosing a plugin name
|
15
15
|
By default the plugin generator will use the name of the directory or the name specified via the -n option. This name
|
16
|
-
will used
|
16
|
+
will be used throughout the generator templates so its important to pick a sensible name. The generator also uses the plugin_name
|
17
17
|
as a class name although you are free to change it after creation.
|
18
18
|
|
19
19
|
### Naming the gem and repo
|
20
20
|
Please ensure the gem name uses the following naming scheme retrospec-plugin_name and that your repo is also named retrospec-plugin_name.
|
21
|
-
This will help everyone identify what the repo and gem do
|
21
|
+
This will help everyone identify what the repo and gem do.
|
22
22
|
|
23
23
|
Note: puppet-retrospec does not follow this standard due to a legacy name issue that would have caused confusion.
|
24
24
|
|
25
25
|
## What you need to override
|
26
|
-
*
|
26
|
+
* self.run_cli
|
27
27
|
|
28
28
|
## Create a context object
|
29
29
|
By default the plugin generator will create a context object that can be used inside templates. The default context object
|
30
30
|
does not contain anything useful so you will want to customize this object only if your templates require variable interpolation.
|
31
31
|
|
32
|
-
##
|
33
|
-
|
34
|
-
To customize these options please override the the following class method:
|
32
|
+
## Main method to override
|
33
|
+
Retrospec will call your plugin by running the plugin.run_cli class method. You can do whatever you want in this method.
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
The global_opts are the options passed into the retrospec command which are specific to retrospec. Additionally, the
|
36
|
+
global_config (~/.retrospec/config.yaml) is a hash map of the entire config while the plugin_config is a subset that pertains
|
37
|
+
only to your plugin.
|
38
|
+
|
39
|
+
In this method you should at least call self.new() on your plugin and then plugin_instance.run.
|
40
|
+
|
41
|
+
For simplicity sake you can also just copy and paste this into your method. This is the default layout when using
|
42
|
+
the retrospec plugin generator.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
def self.run_cli(global_opts, global_config, plugin_config)
|
46
|
+
# a list of subcommands for this plugin
|
47
|
+
sub_commands = []
|
48
|
+
if sub_commands.count > 0
|
49
|
+
sub_command_help = "Subcommands:\n#{sub_commands.join("\n")}\n"
|
50
|
+
else
|
51
|
+
sub_command_help = ""
|
52
|
+
end
|
53
|
+
plugin_opts = Trollop::options do
|
54
|
+
version "#{Retrospec::Pluginname::VERSION} (c) Your Name"
|
55
|
+
banner <<-EOS
|
56
|
+
Some description goes here.\n
|
57
|
+
#{sub_command_help}
|
58
|
+
|
59
|
+
EOS
|
39
60
|
opt :option1, "Some fancy option"
|
61
|
+
stop_on sub_commands
|
62
|
+
end
|
63
|
+
# the passed in options will always override the config file
|
64
|
+
plugin_data = plugin_opts.merge(global_config).merge(global_opts).merge(plugin_opts)
|
65
|
+
# define the default action to use the plugin here, the default is run
|
66
|
+
sub_command = (ARGV.shift || :run).to_sym
|
67
|
+
# create an instance of this plugin
|
68
|
+
plugin = self.new(plugin_data[:module_path],plugin_data)
|
69
|
+
# check if the plugin supports the sub command
|
70
|
+
if plugin.respond_to?(sub_command)
|
71
|
+
plugin.post_init # finish initialization
|
72
|
+
plugin.send(sub_command)
|
73
|
+
else
|
74
|
+
puts "The subcommand #{sub_command} is not supported or valid"
|
75
|
+
exit 1
|
40
76
|
end
|
41
77
|
end
|
42
78
|
```
|
data/retrospec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "retrospec"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corey Osman"]
|
12
|
-
s.date = "2015-
|
12
|
+
s.date = "2015-10-10"
|
13
13
|
s.description = "Retrospec is a framework that allows the automation of repetitive file creation with just about any kind of language through the use of a pluggable architecture."
|
14
14
|
s.email = "corey@logicminds.biz"
|
15
15
|
s.executables = ["retrospec"]
|
@@ -33,7 +33,6 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/retrospec/cli.rb",
|
34
34
|
"lib/retrospec/config.rb",
|
35
35
|
"lib/retrospec/exceptions.rb",
|
36
|
-
"lib/retrospec/module.rb",
|
37
36
|
"lib/retrospec/plugin_loader.rb",
|
38
37
|
"lib/retrospec/plugins.rb",
|
39
38
|
"lib/retrospec/plugins/v1.rb",
|
data/spec/retrospec_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retrospec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -147,7 +147,6 @@ files:
|
|
147
147
|
- lib/retrospec/cli.rb
|
148
148
|
- lib/retrospec/config.rb
|
149
149
|
- lib/retrospec/exceptions.rb
|
150
|
-
- lib/retrospec/module.rb
|
151
150
|
- lib/retrospec/plugin_loader.rb
|
152
151
|
- lib/retrospec/plugins.rb
|
153
152
|
- lib/retrospec/plugins/v1.rb
|
data/lib/retrospec/module.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require_relative 'plugins'
|
2
|
-
require_relative 'exceptions'
|
3
|
-
require_relative 'config'
|
4
|
-
|
5
|
-
module Retrospec
|
6
|
-
class Module
|
7
|
-
include Retrospec::Plugins
|
8
|
-
# module path is the relative or absolute path to the module that we should retrofit
|
9
|
-
# opts hash contains additional flags and options that can be user to control the creation of the tests
|
10
|
-
# opts[:config_map]
|
11
|
-
def initialize(supplied_module_path, plugin_class, opts={})
|
12
|
-
# locates the plugin class that can be used with this module directory
|
13
|
-
begin
|
14
|
-
# load any save data in the config file
|
15
|
-
config_data = Retrospec::Config.config_data(opts[:config_map])
|
16
|
-
plugin_data = Retrospec::Config.plugin_context(config_data, plugin_class.send(:plugin_name))
|
17
|
-
# merge the passed in options
|
18
|
-
plugin_data.merge!(opts)
|
19
|
-
# create the instance of the plugin
|
20
|
-
plugin = plugin_class.send(:new, supplied_module_path, plugin_data)
|
21
|
-
plugin.run
|
22
|
-
rescue NoSuitablePluginFoundException
|
23
|
-
puts "No gem was found to support this code type, please install a gem that supports this module.".fatal
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# finds a suitable plugin given the name of the plugin or via a supported discovery method
|
28
|
-
def find_plugin_type(module_path, name=nil)
|
29
|
-
if name
|
30
|
-
# when the user wants to create a module give the module type
|
31
|
-
discover_plugin_by_name(name)
|
32
|
-
else
|
33
|
-
discover_plugin(module_path)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|