retrospec 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -6
- data/Gemfile.lock +1 -1
- data/README.md +119 -0
- data/VERSION +1 -1
- data/available_plugins.yaml +4 -4
- data/bin/retrospec +1 -21
- data/lib/retrospec.rb +3 -41
- data/lib/retrospec/cli.rb +40 -0
- data/lib/retrospec/module.rb +37 -0
- data/lib/retrospec/plugin_loader.rb +1 -0
- data/lib/retrospec/plugins.rb +17 -2
- data/lib/retrospec/plugins/v1.rb +1 -1
- data/lib/retrospec/plugins/v1/context_object.rb +11 -0
- data/lib/retrospec/plugins/v1/plugin.rb +70 -0
- data/plugin_development.md +45 -0
- data/retrospec.gemspec +8 -5
- data/spec/cli_spec.rb +0 -1
- data/spec/retrospec_spec.rb +1 -1
- metadata +8 -5
- data/README.rdoc +0 -19
- data/lib/retrospec/plugins/v1/instance.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2cd45726cebda553995e231943a0471f733edf4
|
4
|
+
data.tar.gz: c5e151d70b8045fc843b30eeb995344b93a91e37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e32c52220839c540b7a7a6f3461a8b85cfd091a44c49c040c6d1af5e9029ba35b2c3d5c24ff96c4e7fd768c2e4eca7551a34d1372d2f20344f4ec50570b03ae3
|
7
|
+
data.tar.gz: 51ed46bc2d938f5738f67294b60db40ad2562ce6d3982a87a46dce1c4f04fa8e97d2e4545d22bb49d6260ea7ea99df00fa66b84b9d82d06b60cf4d9d75b37544
|
data/Gemfile
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
gem 'trollop'
|
6
|
-
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
3
|
+
|
8
4
|
group :development do
|
9
5
|
gem "rspec", "~> 3.2"
|
10
6
|
gem "rdoc", "~> 3.12"
|
@@ -13,4 +9,4 @@ group :development do
|
|
13
9
|
gem "simplecov", ">= 0"
|
14
10
|
gem 'pry'
|
15
11
|
gem "fakefs", :require => "fakefs/safe"
|
16
|
-
end
|
12
|
+
end
|
data/Gemfile.lock
CHANGED
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Retrospec
|
2
|
+
|
3
|
+
Retrospec is a framework that allows the automation of repetitive project file creation with just about any kind of programming
|
4
|
+
project through the use of a pluggable architecture.
|
5
|
+
|
6
|
+
The idea originally came from another project that performed the same function but was scoped to puppet module creation
|
7
|
+
called [puppet-retrospec](https://github.com/nwops/puppet-retrospec.git). The goal of puppet-retrospec was to document
|
8
|
+
the workflow and its best practices inside templates. This idea has now been generalized to cover any kind of project,
|
9
|
+
therefore making it dead simple for anybody to get their project started with a simple command.
|
10
|
+
|
11
|
+
There are two scenarios that this gem can be used for.
|
12
|
+
1. Initial project creation
|
13
|
+
2. Project augmentation
|
14
|
+
|
15
|
+
The first scenario is to aid the creation of the project as many times information is spread across people, teams, blogs,
|
16
|
+
forums and is often out of date. By keeping this information in templates we have removed the burden of finding this
|
17
|
+
information from the user. However, there are many tools in existence today that already help in this area, but they
|
18
|
+
are often not customizable.
|
19
|
+
|
20
|
+
The second scenario it to augment an existing project that a user may have already started. When this is the case
|
21
|
+
retrospec can "retrofit" an existing project with the latest workflow and best practices based on the templates inside
|
22
|
+
a plugin gem. An existing project also contains information that can be used to automatically generate lots of files beyond just
|
23
|
+
initial module creation. A great example of this is with [puppet-retrospec](https://github.com/nwops/puppet-retrospec.git),
|
24
|
+
where the goal is to automaticly generate valid unit tests based on the code the author wrote. So as the user writes more
|
25
|
+
code, they can easily create unit test files by just running retrospec.
|
26
|
+
|
27
|
+
Furthermore, retrospec is meant to be run multiple times during a project lifecycle in order to augment it with new files.
|
28
|
+
Because of the safe file creation, no file can be overwritten so the only way to overcome this is to manually delete the
|
29
|
+
file and let retrospec recreate it automatically.
|
30
|
+
|
31
|
+
This idea is inspried by a few projects:
|
32
|
+
|
33
|
+
- maven archetypes
|
34
|
+
- jeweler ruby gem
|
35
|
+
- puppet-lint
|
36
|
+
|
37
|
+
## Install
|
38
|
+
|
39
|
+
`gem install retrospec`
|
40
|
+
|
41
|
+
## Known issues
|
42
|
+
If you have previously installed the puppet-retrospec gem, there is a conflict with the executable file `retrospec` because
|
43
|
+
this gem also uses an executable file with the same name. As a result I will be moving the legacy puppet-retrospec gem
|
44
|
+
to a retrospec plugin that performs the same functionality. But first I have to release this gem and the plugingem in order
|
45
|
+
to move the puppet-retrospec to a plugin.
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
### List Available Plugins
|
50
|
+
By default the retrospec gem does not do anything but provide a framework for plugins. In order to do anything you will
|
51
|
+
need to install a retrospec plugin. To see a list of plugins use: `retrospec -a` which will query the following [url](https://raw.githubusercontent.com/nwops/retrospec/master/available_plugins.yaml).
|
52
|
+
|
53
|
+
|
54
|
+
### Setting the module path
|
55
|
+
Setting the module path is the only option that can change the outcome of the plugin. By default it will use the current
|
56
|
+
directory, but this can be overridden by using the `retrospec -m` option.
|
57
|
+
|
58
|
+
### Subcommands
|
59
|
+
Subcommands are added dynamically to the help screen when installing new retrospec plugins.
|
60
|
+
So just use `retrospec -h` to see the list. The name of the plugin is usually the name of subcommand.
|
61
|
+
|
62
|
+
```
|
63
|
+
retrospec -h
|
64
|
+
A framework to automate your development workflow by generating common files and test patterns.
|
65
|
+
|
66
|
+
Usage: retrospec [global options] subcommand [subcommand options]
|
67
|
+
Available subcommands:
|
68
|
+
plugingen
|
69
|
+
-m, --module-path=<s> The path (relative or absolute) to the module directory (default: /Users/cosman/github/retrospec)
|
70
|
+
-a, --available-plugins Show an online list of available plugins
|
71
|
+
-v, --version Print version and exit
|
72
|
+
-h, --help Show this message
|
73
|
+
```
|
74
|
+
|
75
|
+
Note: If you are really good at Trollop and can suggest a better way to display subcommands please let me know. I was going
|
76
|
+
for a git like interface but came up short.
|
77
|
+
|
78
|
+
### Using subcommands
|
79
|
+
Once you find the subcommand you want just run the subcommand like: `retrospec -m tmp/test4 plugingen`. If you
|
80
|
+
have already created your project you don't need to pass the `-m` option if your current working directory
|
81
|
+
is the root of your project. So you may find yourself running `retrospec plugin_name` often inside your project.
|
82
|
+
|
83
|
+
Getting help with a subcommand is easy as using `retrospec -m tmp/test4 plugin_name -h`
|
84
|
+
|
85
|
+
```
|
86
|
+
% retrospec -m /tmp/new_retrospec_plugin plugingen -h
|
87
|
+
Options:
|
88
|
+
-n, --name=<s> The name of the new plugin (default: new_retrospec_plugin)
|
89
|
+
-h, --help Show this message
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
### Retrspec config file
|
94
|
+
Retrospec will read the config file at ~/.retrospec/config.yaml for configs related to retrospec itself or any plugins
|
95
|
+
you install. Since you may be running retrospec over and over it will be annoying to always have to specify this info
|
96
|
+
so please refer to the plugin documentation for which options you can save to the config file. At this time there are
|
97
|
+
no retrospec config options being read form the config file. By default retrospec will add a simple config to ~/.retrospec
|
98
|
+
|
99
|
+
## Plugins
|
100
|
+
Please see the following [list](https://raw.githubusercontent.com/nwops/retrospec/master/available_plugins.yaml) for available plugins.
|
101
|
+
|
102
|
+
|
103
|
+
## Plugin development
|
104
|
+
Please see the [plugin document](plugin_development.md) for creating new retrospec plugins.
|
105
|
+
|
106
|
+
== Contributing to retrospec
|
107
|
+
|
108
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
109
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
110
|
+
* Fork the project.
|
111
|
+
* Start a feature/bugfix branch.
|
112
|
+
* Commit and push until you are happy with your contribution.
|
113
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
114
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
115
|
+
|
116
|
+
== Copyright
|
117
|
+
|
118
|
+
Copyright (c) 2015 Corey Osman. See LICENSE.txt for
|
119
|
+
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/available_plugins.yaml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
retrospec-
|
3
|
-
project_url: https://github.com/nwops/retrospec-
|
4
|
-
gem: retrospec-
|
5
|
-
description: Provides
|
2
|
+
retrospec-plugingen:
|
3
|
+
project_url: https://github.com/nwops/retrospec-plugingen
|
4
|
+
gem: retrospec-plugingen
|
5
|
+
description: Provides instant retrospec plugin creation
|
data/bin/retrospec
CHANGED
@@ -1,25 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require_relative '../lib/retrospec/cli'
|
3
|
-
require 'trollop'
|
4
3
|
|
5
|
-
opts = Trollop::options do
|
6
|
-
version "0.1.0 (c) Corey Osman"
|
7
|
-
banner <<-EOS
|
8
|
-
A framework to automate your development workflow by generating common files and test patterns.
|
9
|
-
|
10
|
-
|
11
|
-
EOS
|
12
|
-
opt :module_path, "The path (relative or absolute) to the module directory (Defaults to current directory) " ,
|
13
|
-
:type => :string, :required => false, :default => nil
|
14
|
-
opt :installed_plugins, "List the installed plugins", :type => :boolean, :require => false
|
15
|
-
opt :available_plugins, "Show an online list of available plugins", :type => :boolean, :require => false
|
16
|
-
|
17
|
-
end
|
18
|
-
if opts[:installed_plugins]
|
19
|
-
Retrospec::Cli.list_installed_plugins
|
20
|
-
end
|
21
|
-
|
22
|
-
if opts[:available_plugins]
|
23
|
-
Retrospec::Cli.list_available_plugins
|
24
|
-
end
|
25
4
|
|
5
|
+
Retrospec::Cli.run
|
data/lib/retrospec.rb
CHANGED
@@ -1,43 +1,6 @@
|
|
1
|
-
|
2
|
-
require 'retrospec/exceptions'
|
3
|
-
require 'retrospec/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, opts={})
|
12
|
-
# locates the plugin class that can be used with this module directory
|
13
|
-
begin
|
14
|
-
opts[:name] ||= File.basename(supplied_module_path) # use the name or derive it from the dir name
|
15
|
-
plugin_class = find_plugin_type(supplied_module_path, opts[:name])
|
16
|
-
# load any save data in the config file
|
17
|
-
config_data = Retrospec::Config.config_data(opts[:config_map])
|
18
|
-
plugin_data = Retrospec::Config.plugin_context(config_data, plugin_class.send(:plugin_name))
|
19
|
-
# merge the passed in options
|
20
|
-
plugin_data.merge!(opts)
|
21
|
-
# create the instance of the plugin
|
22
|
-
plugin = plugin_class.send(:new, supplied_module_path, plugin_data)
|
23
|
-
plugin.run
|
24
|
-
rescue NoSuitablePluginFoundException
|
25
|
-
puts "No gem was found to support this code type, please install a gem that supports this module.".fatal
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# finds a suitable plugin given the name of the plugin or via a supported discovery method
|
30
|
-
def find_plugin_type(module_path, name=nil)
|
31
|
-
if name
|
32
|
-
# when the user wants to create a module give the module type
|
33
|
-
discover_plugin_by_name(name)
|
34
|
-
else
|
35
|
-
discover_plugin(module_path)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
require_relative 'retrospec/module'
|
40
2
|
|
3
|
+
# monkey patch in some color effects string methods
|
41
4
|
class String
|
42
5
|
def red; "\033[31m#{self}\033[0m" end
|
43
6
|
def green; "\033[32m#{self}\033[0m" end
|
@@ -46,5 +9,4 @@ class String
|
|
46
9
|
def warning; yellow end
|
47
10
|
def fatal; red end
|
48
11
|
def info; green end
|
49
|
-
end
|
50
|
-
|
12
|
+
end
|
data/lib/retrospec/cli.rb
CHANGED
@@ -1,9 +1,49 @@
|
|
1
1
|
require_relative 'plugins'
|
2
|
+
require 'trollop'
|
3
|
+
require_relative '../retrospec'
|
2
4
|
|
3
5
|
module Retrospec
|
4
6
|
class Cli
|
5
7
|
include Retrospec::Plugins
|
6
8
|
|
9
|
+
def self.run
|
10
|
+
cli = Retrospec::Cli.new
|
11
|
+
sub_commands = cli.plugin_map.keys
|
12
|
+
cmd_help = sub_commands.join("\n")
|
13
|
+
|
14
|
+
global_opts = Trollop::options do
|
15
|
+
version "0.1.0 (c) Corey Osman"
|
16
|
+
banner <<-EOS
|
17
|
+
A framework to automate your development workflow by generating common files and test patterns.
|
18
|
+
|
19
|
+
Usage: retrospec [global options] subcommand [subcommand options]
|
20
|
+
Available subcommands:
|
21
|
+
#{cmd_help}
|
22
|
+
|
23
|
+
EOS
|
24
|
+
opt :module_path, "The path (relative or absolute) to the module directory" ,
|
25
|
+
:type => :string, :required => false, :default => File.expand_path('.')
|
26
|
+
opt :available_plugins, "Show an online list of available plugins", :type => :boolean, :require => false, :short => '-a'
|
27
|
+
stop_on sub_commands
|
28
|
+
end
|
29
|
+
cmd = ARGV.shift # get the subcommand
|
30
|
+
if plugin_class = cli.plugin_map[cmd]
|
31
|
+
# run the subcommand options
|
32
|
+
cmd_opts = cli.plugin_map[cmd].send(:cli_options, global_opts)
|
33
|
+
opts = global_opts.merge(cmd_opts)
|
34
|
+
Retrospec::Module.new(global_opts[:module_path], plugin_class, opts)
|
35
|
+
else
|
36
|
+
if global_opts[:available_plugins]
|
37
|
+
Retrospec::Cli.list_available_plugins
|
38
|
+
else
|
39
|
+
# this is the default action when no command is entered
|
40
|
+
# at a later time we will try and use some magic to guess
|
41
|
+
# what the user wants
|
42
|
+
Trollop.educate
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
7
47
|
def self.list_available_plugins
|
8
48
|
Retrospec::Cli.new.available_plugins.each do |name, plugin_data|
|
9
49
|
puts "#{name}: #{plugin_data['project_url']}"
|
@@ -0,0 +1,37 @@
|
|
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
|
data/lib/retrospec/plugins.rb
CHANGED
@@ -15,8 +15,14 @@ module Retrospec
|
|
15
15
|
def plugin_classes
|
16
16
|
unless @plugin_classes
|
17
17
|
load_plugins
|
18
|
-
@plugin_classes = ObjectSpace.each_object(Class).find_all {|c| c.name =~ /Retrospec::Plugins/}
|
18
|
+
@plugin_classes = ObjectSpace.each_object(Class).find_all {|c| c.name =~ /Retrospec::Plugins/} - [Retrospec::Plugins::V1::Plugin]|| []
|
19
|
+
|
19
20
|
end
|
21
|
+
@plugin_classes
|
22
|
+
end
|
23
|
+
|
24
|
+
def plugin_map
|
25
|
+
@plugin_map ||= Hash[plugin_classes.map { |gem| [gem.send(:plugin_name) , gem] }]
|
20
26
|
end
|
21
27
|
|
22
28
|
def installed_plugins
|
@@ -38,8 +44,17 @@ module Retrospec
|
|
38
44
|
plugin
|
39
45
|
end
|
40
46
|
|
47
|
+
def gem_dir
|
48
|
+
File.expand_path("../../../", __FILE__)
|
49
|
+
end
|
50
|
+
|
41
51
|
def available_plugins
|
42
|
-
|
52
|
+
begin
|
53
|
+
get_remote_data('https://raw.githubusercontent.com/nwops/retrospec/master/available_plugins.yaml')
|
54
|
+
rescue SocketError
|
55
|
+
puts "Using cached list of available plugins, use internet to get latest list."
|
56
|
+
YAML.load_file(File.join(gem_dir, 'available_plugins.yaml'))
|
57
|
+
end
|
43
58
|
end
|
44
59
|
|
45
60
|
def get_remote_data(url)
|
data/lib/retrospec/plugins/v1.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative 'v1/
|
1
|
+
require_relative 'v1/plugin'
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
require_relative 'module_helpers'
|
3
|
+
|
4
|
+
module Retrospec
|
5
|
+
module Plugins
|
6
|
+
module V1
|
7
|
+
class Plugin
|
8
|
+
attr_accessor :module_path, :config_data
|
9
|
+
attr_reader :plugin_name
|
10
|
+
|
11
|
+
# by including this module we are getting helper code that will assist
|
12
|
+
# with creating files and rendering template.
|
13
|
+
# for a list of available functions please see the following lik
|
14
|
+
# https://github.com/nwops/retrospec/blob/master/lib/retrospec/plugins/v1/module_helpers.rb
|
15
|
+
include Retrospec::Plugins::V1::ModuleHelpers
|
16
|
+
|
17
|
+
def initialize(supplied_module_path='.',config={})
|
18
|
+
@config_data = config
|
19
|
+
@module_path = File.expand_path(supplied_module_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
# validates that the module meets the plugins criteria
|
23
|
+
# returns boolean true if module files are valid, false otherwise
|
24
|
+
# validates module directory fits the description of this plugin
|
25
|
+
# this is used in the discover method
|
26
|
+
def self.valid_module_dir?(dir)
|
27
|
+
if ! File.exist?(dir)
|
28
|
+
false
|
29
|
+
else
|
30
|
+
module_files ||= Dir.glob("#{dir}/**/*#{file_type}")
|
31
|
+
if module_files.length < 1
|
32
|
+
false
|
33
|
+
else
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# used to display subcommand options to the cli
|
40
|
+
# the global options are passed in for your usage
|
41
|
+
def self.cli_options(global_opts)
|
42
|
+
Trollop::options do
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# the name of the plugin that will be sent to the cli
|
47
|
+
# the cli turns this into a subcommand where the user interacts with your plugin
|
48
|
+
def self.plugin_name
|
49
|
+
self.name.split('::').last.downcase
|
50
|
+
end
|
51
|
+
|
52
|
+
# sets the config which should be a hash
|
53
|
+
def config=(config_map)
|
54
|
+
@config = config_map
|
55
|
+
end
|
56
|
+
|
57
|
+
# the main file type that is used to help discover what the module is
|
58
|
+
def self.file_type
|
59
|
+
raise NotImplementedError
|
60
|
+
end
|
61
|
+
|
62
|
+
# the main entry point that is called when retrospec is run
|
63
|
+
# using this as the starting point after initialization
|
64
|
+
def run
|
65
|
+
raise NotImplementedError
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Retrospec plugin development
|
2
|
+
|
3
|
+
If you wish to automate the creation of a project or other project plugins you should
|
4
|
+
create a retrospec plugin. Follow the steps below to create a plugin.
|
5
|
+
|
6
|
+
## Creating a plugin using the plugin generator
|
7
|
+
1. Install the retrospec plugin that creates retrospec plugins! `gem install retrospec-plugingen`
|
8
|
+
2. Come up with a name for you plugin.
|
9
|
+
3. Use the retrospec plugin help `retrospec -m /path_to_project/plugin_name plugingen -h`
|
10
|
+
4. Create the plugin `retrospec -m /path_to_project/plugin_name plugingen`
|
11
|
+
5. Open the /path_to_project/plugin_name in your favorite editor
|
12
|
+
6. Hack --> Test --> Publish
|
13
|
+
|
14
|
+
## Choosing a plugin name
|
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 through the generator templates so its important to pick a sensible name. The generator also uses the plugin_name
|
17
|
+
as a class name although you are free to change it after creation.
|
18
|
+
|
19
|
+
## What you need to override
|
20
|
+
* run
|
21
|
+
|
22
|
+
## Create a context object
|
23
|
+
By default the plugin generator will create a context object that can be used inside templates. The default context object
|
24
|
+
does not contain anything useful so you will want to customize this object only if your templates require variable interpolation.
|
25
|
+
|
26
|
+
## Add custom options to the cli
|
27
|
+
You can get input from the user in the form of cli options. These options are passed in directly to your init method.
|
28
|
+
To customize these options please override the the following class method:
|
29
|
+
|
30
|
+
```
|
31
|
+
def self.cli_options(global_opts)
|
32
|
+
Trollop::options do
|
33
|
+
opt :option1, "Some fancy option"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
See the [trollop documentation](http://trollop.rubyforge.org) for more info.
|
39
|
+
|
40
|
+
## Module helpers
|
41
|
+
The module helpers module is included by default and contains useful methods to safely create files. When creating files
|
42
|
+
use the safe create methods in order to protect the users content from being overwritten.
|
43
|
+
For a list of methods please see the [source code](https://github.com/nwops/retrospec/blob/master/lib/retrospec/plugins/v1/module_helpers.rb)
|
44
|
+
|
45
|
+
|
data/retrospec.gemspec
CHANGED
@@ -5,17 +5,17 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "retrospec"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.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-09-
|
12
|
+
s.date = "2015-09-26"
|
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"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE.txt",
|
18
|
-
"README.
|
18
|
+
"README.md"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".document",
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
"Gemfile",
|
24
24
|
"Gemfile.lock",
|
25
25
|
"LICENSE.txt",
|
26
|
-
"README.
|
26
|
+
"README.md",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"available_plugins.yaml",
|
@@ -33,11 +33,14 @@ 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",
|
36
37
|
"lib/retrospec/plugin_loader.rb",
|
37
38
|
"lib/retrospec/plugins.rb",
|
38
39
|
"lib/retrospec/plugins/v1.rb",
|
39
|
-
"lib/retrospec/plugins/v1/
|
40
|
+
"lib/retrospec/plugins/v1/context_object.rb",
|
40
41
|
"lib/retrospec/plugins/v1/module_helpers.rb",
|
42
|
+
"lib/retrospec/plugins/v1/plugin.rb",
|
43
|
+
"plugin_development.md",
|
41
44
|
"retrospec.gemspec",
|
42
45
|
"spec/cli_spec.rb",
|
43
46
|
"spec/config_spec.rb",
|
data/spec/cli_spec.rb
CHANGED
data/spec/retrospec_spec.rb
CHANGED
@@ -2,5 +2,5 @@ require 'spec_helper'
|
|
2
2
|
require 'retrospec'
|
3
3
|
|
4
4
|
describe "Retrospec" do
|
5
|
-
it {expect
|
5
|
+
it {expect{Retrospec::Module.new('/Users/cosman/github/puppetlabs-apache', Retrospec::Plugins::V1::Plugin)}.to raise_error NotImplementedError }
|
6
6
|
end
|
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.2.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-09-
|
11
|
+
date: 2015-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -130,14 +130,14 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files:
|
132
132
|
- LICENSE.txt
|
133
|
-
- README.
|
133
|
+
- README.md
|
134
134
|
files:
|
135
135
|
- .document
|
136
136
|
- .rspec
|
137
137
|
- Gemfile
|
138
138
|
- Gemfile.lock
|
139
139
|
- LICENSE.txt
|
140
|
-
- README.
|
140
|
+
- README.md
|
141
141
|
- Rakefile
|
142
142
|
- VERSION
|
143
143
|
- available_plugins.yaml
|
@@ -147,11 +147,14 @@ files:
|
|
147
147
|
- lib/retrospec/cli.rb
|
148
148
|
- lib/retrospec/config.rb
|
149
149
|
- lib/retrospec/exceptions.rb
|
150
|
+
- lib/retrospec/module.rb
|
150
151
|
- lib/retrospec/plugin_loader.rb
|
151
152
|
- lib/retrospec/plugins.rb
|
152
153
|
- lib/retrospec/plugins/v1.rb
|
153
|
-
- lib/retrospec/plugins/v1/
|
154
|
+
- lib/retrospec/plugins/v1/context_object.rb
|
154
155
|
- lib/retrospec/plugins/v1/module_helpers.rb
|
156
|
+
- lib/retrospec/plugins/v1/plugin.rb
|
157
|
+
- plugin_development.md
|
155
158
|
- retrospec.gemspec
|
156
159
|
- spec/cli_spec.rb
|
157
160
|
- spec/config_spec.rb
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= retrospec
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to retrospec
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
-
* Fork the project.
|
10
|
-
* Start a feature/bugfix branch.
|
11
|
-
* Commit and push until you are happy with your contribution.
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2015 Corey Osman. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Retrospec
|
2
|
-
module Plugin
|
3
|
-
module V1
|
4
|
-
attr_accessor :module_path, :module_name, :module_dir_name, :config
|
5
|
-
attr_reader :files, :plugin_name
|
6
|
-
|
7
|
-
# validates that the module meets the plugins criteria
|
8
|
-
# returns boolean true if module files are valid, false otherwise
|
9
|
-
# validates module directory fits the description of this plugin
|
10
|
-
def self.valid_module_dir?(dir)
|
11
|
-
if ! File.exist?(dir)
|
12
|
-
false
|
13
|
-
else
|
14
|
-
module_files ||= Dir.glob("#{dir}/**/*#{file_type}")
|
15
|
-
if module_files.length < 1
|
16
|
-
false
|
17
|
-
else
|
18
|
-
true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# sets the config which should be a hash
|
24
|
-
def config=(config_map)
|
25
|
-
@config = config_map
|
26
|
-
end
|
27
|
-
|
28
|
-
# the name of the plugin, defaults to the name of the class
|
29
|
-
def self.plugin_name
|
30
|
-
self.class.downcase
|
31
|
-
end
|
32
|
-
|
33
|
-
# the main file type that is used to help discover what the module is
|
34
|
-
def self.file_type
|
35
|
-
raise NotImplementedError
|
36
|
-
end
|
37
|
-
|
38
|
-
def run
|
39
|
-
raise NotImplementedError
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|