pigtail 0.0.1.17
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 +7 -0
- data/Gemfile +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +78 -0
- data/Rakefile +17 -0
- data/bin/pigtail +24 -0
- data/bin/pigtailize +68 -0
- data/lib/pigtail/command_line.rb +135 -0
- data/lib/pigtail/config.rb +47 -0
- data/lib/pigtail/configs.rb +132 -0
- data/lib/pigtail/output_config.rb +32 -0
- data/lib/pigtail/setup.rb +11 -0
- data/lib/pigtail/version.rb +3 -0
- data/lib/pigtail.rb +15 -0
- data/pigtail.gemspec +24 -0
- data/test/functional/#setup_test.rb# +85 -0
- data/test/functional/command_line_test.rb +38 -0
- data/test/functional/setup_test.rb +70 -0
- data/test/pigtail_test.rb +7 -0
- data/test/test_case.rb +39 -0
- data/test/test_helper.rb +16 -0
- data/test/unit/config_test.rb +82 -0
- data/test/unit/output_config_test.rb +4 -0
- metadata +121 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: e8aed587afcec2ae4c4778dc261d31d2d5bd7911
|
|
4
|
+
data.tar.gz: c6d47a99d9667856abe45601996e9bd52b93969b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 08fcd3f2eda95c5a1cf9f18b533c141da150533b365ced6d12c33effaeae0b1cf564fdce9986d4f7d8c842e5488b086862c14e250105e5f8a86f7940672d6d91
|
|
7
|
+
data.tar.gz: d5d9ff35417313aaeb7cd2e5fc68c5559ab9b666616b1a70ab0ff48bafccb5a2d2c73aaf0437e1d7dcef10b49156646c367f1c9238ce0e9659ed79facc9a3f69
|
data/Gemfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
# Declare your gem's dependencies in pigtail.gemspec.
|
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
|
5
|
+
# development dependencies will be added by default to the :development group.
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
|
11
|
+
# your gem to rubygems.org.
|
|
12
|
+
|
|
13
|
+
# To use a debugger
|
|
14
|
+
# gem 'byebug', group: [:development, :test]
|
|
15
|
+
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2015 Nab Inno
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Pigtail is a Ruby gem that provides a clear syntax for writing configurations.
|
|
2
|
+
|
|
3
|
+
### Installation
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
$ gem install pigtail
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Or with Bundler in your Gemfile.
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'pigtail'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Getting started
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
$ cd /apps/my-great-project
|
|
19
|
+
$ pigtailize .
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
This will create an initial `config/pigtail.rb` file for you.
|
|
23
|
+
|
|
24
|
+
### Example config/pigtail.rb file
|
|
25
|
+
|
|
26
|
+
Pigtail ships with three pre-defined config types: command, runner, and rake. You can define your own with `config_type`.
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
config_type :sports, <<-YAML
|
|
30
|
+
global:
|
|
31
|
+
- category: :task
|
|
32
|
+
place: :place
|
|
33
|
+
log: :log
|
|
34
|
+
feeds:
|
|
35
|
+
- http://www.example.com/ski_1.rss
|
|
36
|
+
- http://www.example.com/ski_2.rss
|
|
37
|
+
YAML
|
|
38
|
+
set :log, "/path/to/my/sports.log"
|
|
39
|
+
|
|
40
|
+
to "foo/bar" do
|
|
41
|
+
sports "ski", {
|
|
42
|
+
place: "/japan/nagano"
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Would configure `global: foo` to "/bar/buzz". `:task` is always replaced with the first argument, and any additional hash arguments are replaced with the options passed in or by variables that have been defined with `set`.
|
|
48
|
+
|
|
49
|
+
### The `pigtail` command
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
$ cd /apps/my-great-project
|
|
53
|
+
$ pigtail
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This will simply show you your `config/pigtail.rb` file converted to cron syntax. It does not read or write your crontab file. Run `pigtail --help` for a complete list of options.
|
|
57
|
+
|
|
58
|
+
### Acknowledgement
|
|
59
|
+
|
|
60
|
+
Pigtail is based heavily on Whenever.
|
|
61
|
+
|
|
62
|
+
### Epilogue
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
A whale!
|
|
66
|
+
Down it goes, and more, and more
|
|
67
|
+
Up goes its tail!
|
|
68
|
+
|
|
69
|
+
-Buson Yosa
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
----
|
|
73
|
+
|
|
74
|
+
Compatible with Ruby 1.8.7-2.2.0, JRuby, and Rubinius. [](http://travis-ci.org/nabinno/pigtail)
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
Copyright © 2015 Nab Inno
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler'
|
|
3
|
+
rescue LoadError => e
|
|
4
|
+
warn("warning: Could not load bundler: #{e}")
|
|
5
|
+
warn(" Some rake tasks will not be defined")
|
|
6
|
+
else
|
|
7
|
+
Bundler::GemHelper.install_tasks
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require 'rake/testtask'
|
|
11
|
+
Rake::TestTask.new(:test) do |test|
|
|
12
|
+
test.libs << 'lib' << 'test'
|
|
13
|
+
test.pattern = 'test/{functional,unit}/**/*_test.rb'
|
|
14
|
+
test.verbose = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
task :default => :test
|
data/bin/pigtail
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'pigtail'
|
|
5
|
+
require 'pigtail/version'
|
|
6
|
+
|
|
7
|
+
options = {}
|
|
8
|
+
|
|
9
|
+
OptionParser.new do |opts|
|
|
10
|
+
opts.banner = "Usage: pigtail [options]"
|
|
11
|
+
opts.on('-w', '--write-plagger-configs [identifier]', 'Default: full path to pigtail_config.rb file') do |identifier|
|
|
12
|
+
options[:write] = true
|
|
13
|
+
options[:identifier] = identifier if identifier
|
|
14
|
+
end
|
|
15
|
+
opts.on('-s', '--set [variables]', 'Example: --set \'environment=staging&path=/my/sweet/path\'') do |set|
|
|
16
|
+
options[:set] = set if set
|
|
17
|
+
end
|
|
18
|
+
opts.on('-f', '--load-file [pigtail file]', 'Default: config/pigtail_config.rb') do |file|
|
|
19
|
+
options[:file] = file if file
|
|
20
|
+
end
|
|
21
|
+
opts.on('-v', '--version') { puts "Pigtail v#{Pigtail::VERSION}"; exit(0) }
|
|
22
|
+
end.parse!
|
|
23
|
+
|
|
24
|
+
Pigtail::CommandLine.execute(options)
|
data/bin/pigtailize
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
|
|
6
|
+
OptionParser.new do |opts|
|
|
7
|
+
opts.banner = "Usage: #{File.basename($0)} [path]"
|
|
8
|
+
|
|
9
|
+
begin
|
|
10
|
+
opts.parse!(ARGV)
|
|
11
|
+
rescue OptionParser::ParseError => e
|
|
12
|
+
warn e.message
|
|
13
|
+
puts opts
|
|
14
|
+
exit 1
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
unless ARGV.empty?
|
|
19
|
+
if !File.exists?(ARGV.first)
|
|
20
|
+
abort "`#{ARGV.first}' does not exist."
|
|
21
|
+
elsif !File.directory?(ARGV.first)
|
|
22
|
+
abort "`#{ARGV.first}' is not a directory."
|
|
23
|
+
elsif ARGV.length > 1
|
|
24
|
+
abort "Too many arguments; please specify only the directory to pigtailize."
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
content = <<-FILE
|
|
29
|
+
# Use this file to easily define all of your configs.
|
|
30
|
+
|
|
31
|
+
# Example:
|
|
32
|
+
#
|
|
33
|
+
# config_type :sports, <<-YAML
|
|
34
|
+
# global:
|
|
35
|
+
# - category: :task
|
|
36
|
+
# place: :place
|
|
37
|
+
# log: :log
|
|
38
|
+
# feeds:
|
|
39
|
+
# - http://www.example.com/ski_1.rss
|
|
40
|
+
# - http://www.example.com/ski_2.rss
|
|
41
|
+
# YAML
|
|
42
|
+
# set :log, "/path/to/my/sports.log"
|
|
43
|
+
#
|
|
44
|
+
# to "foo/bar" do
|
|
45
|
+
# sports "ski", {
|
|
46
|
+
# place: "/japan/nagano"
|
|
47
|
+
# }
|
|
48
|
+
# end
|
|
49
|
+
|
|
50
|
+
# Learn more: http://github.com/nabinno/pigtail
|
|
51
|
+
FILE
|
|
52
|
+
|
|
53
|
+
file = 'config/pigtail.rb'
|
|
54
|
+
base = ARGV.empty? ? '.' : ARGV.shift
|
|
55
|
+
|
|
56
|
+
file = File.join(base, file)
|
|
57
|
+
if File.exists?(file)
|
|
58
|
+
warn "[skip] `#{file}' already exists"
|
|
59
|
+
elsif File.exists?(file.downcase)
|
|
60
|
+
warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
|
|
61
|
+
elsif !File.exists?(File.dirname(file))
|
|
62
|
+
warn "[skip] directory `#{File.dirname(file)}' does not exist"
|
|
63
|
+
else
|
|
64
|
+
puts "[add] writing `#{file}'"
|
|
65
|
+
File.open(file, "w") { |f| f.write(content) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
puts "[done] pigtailize!"
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
module Pigtail
|
|
4
|
+
class CommandLine
|
|
5
|
+
|
|
6
|
+
def self.execute(options={})
|
|
7
|
+
new(options).run
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def initialize(options={})
|
|
11
|
+
@options = options
|
|
12
|
+
@options[:file] ||= 'config/pigtail.rb'
|
|
13
|
+
@options[:identifier] ||= default_identifier
|
|
14
|
+
# @options[:cut] ||= 0
|
|
15
|
+
|
|
16
|
+
if !File.exists?(@options[:file]) && @options[:clear].nil?
|
|
17
|
+
warn("[fail] Can't find file: #{@options[:file]}")
|
|
18
|
+
exit(1)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# if [@options[:update], @options[:write], @options[:clear]].compact.length > 1
|
|
22
|
+
# warn("[fail] Can only update, write or clear. Choose one.")
|
|
23
|
+
# exit(1)
|
|
24
|
+
# end
|
|
25
|
+
|
|
26
|
+
# unless @options[:cut].to_s =~ /[0-9]*/
|
|
27
|
+
# warn("[fail] Can't cut negative lines from the pigtail_config #{options[:cut]}")
|
|
28
|
+
# exit(1)
|
|
29
|
+
# end
|
|
30
|
+
# @options[:cut] = @options[:cut].to_i
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def run
|
|
34
|
+
# if @options[:update] || @options[:clear]
|
|
35
|
+
# write_pigtail_config(updated_pigtail_config)
|
|
36
|
+
# elsif @options[:write]
|
|
37
|
+
if @options[:write]
|
|
38
|
+
write_pigtail_config(pigtail_configs)
|
|
39
|
+
else
|
|
40
|
+
puts Pigtail.configs(@options)
|
|
41
|
+
puts "## [message] Above is your pigtail_config file converted to config syntax; your pigtail_config file was not updated."
|
|
42
|
+
puts "## [message] Run `pigtail --help' for more options."
|
|
43
|
+
exit(0)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
protected
|
|
48
|
+
|
|
49
|
+
def default_identifier
|
|
50
|
+
File.expand_path(@options[:file])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def pigtail_configs
|
|
54
|
+
# return '' if @options[:clear]
|
|
55
|
+
Pigtail.configs(@options)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# def read_pigtail_config
|
|
59
|
+
# return @current_pigtail_config if @current_pigtail_config
|
|
60
|
+
# @current_pigtail_config = ""
|
|
61
|
+
# # @current_pigtail_config = pigtail_configs.nil? ? '' : prepare(pigtail_configs)
|
|
62
|
+
# end
|
|
63
|
+
|
|
64
|
+
def write_pigtail_config(contents)
|
|
65
|
+
contents.each do |content|
|
|
66
|
+
content_path = content[:path]
|
|
67
|
+
content_configure = content[:configure]
|
|
68
|
+
system("mkdir -p " + File.dirname(content_path))
|
|
69
|
+
IO.popen("cat >" + content_path, 'r+') do |io|
|
|
70
|
+
configure = ([comment_open, content_configure, comment_close].compact.join("\n") + "\n")
|
|
71
|
+
io.write(configure)
|
|
72
|
+
io.close_write
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
success = $?.exitstatus.zero?
|
|
76
|
+
|
|
77
|
+
if success
|
|
78
|
+
action = 'written' if @options[:write]
|
|
79
|
+
# action = 'updated' if @options[:update]
|
|
80
|
+
puts "[write] pigtail file #{action} to #{content_path}"
|
|
81
|
+
else
|
|
82
|
+
warn "[fail] Couldn't write pigtail to #{content_path}; try running `pigtail' with no options to ensure your config file is valid."
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# def updated_pigtail_config
|
|
88
|
+
# # Check for unopened or unclosed identifier blocks
|
|
89
|
+
# if (read_pigtail_config =~ Regexp.new("^#{comment_open}\s*$") &&
|
|
90
|
+
# (read_pigtail_config =~ Regexp.new("^#{comment_close}\s*$")).nil?)
|
|
91
|
+
# warn "[fail] Unclosed indentifier; Your pigtail_config file contains '#{comment_open}', but no '#{comment_close}'"
|
|
92
|
+
# exit(1)
|
|
93
|
+
# elsif ((read_pigtail_config =~ Regexp.new("^#{comment_open}\s*$")).nil? &&
|
|
94
|
+
# read_pigtail_config =~ Regexp.new("^#{comment_close}\s*$"))
|
|
95
|
+
# warn "[fail] Unopened indentifier; Your pigtail_config file contains '#{comment_close}', but no '#{comment_open}'"
|
|
96
|
+
# exit(1)
|
|
97
|
+
# end
|
|
98
|
+
#
|
|
99
|
+
# # If an existing identier block is found, replace it with the new pigtail config entries
|
|
100
|
+
# if (read_pigtail_config =~ Regexp.new("^#{comment_open}\s*$") &&
|
|
101
|
+
# read_pigtail_config =~ Regexp.new("^#{comment_close}\s*$"))
|
|
102
|
+
# # If the existing pigtail_config file contains backslashes they get lost going through gsub.
|
|
103
|
+
# # .gsub('\\', '\\\\\\') preserves them. Go figure.
|
|
104
|
+
# read_pigtail_config.gsub(Regexp.new("^#{comment_open}\s*$.+^#{comment_close}\s*$", Regexp::MULTILINE),
|
|
105
|
+
# pigtail_configs[:configure].chomp.gsub('\\', '\\\\\\'))
|
|
106
|
+
# else # Otherwise, append the new pigtail config entries after any existing ones
|
|
107
|
+
# [read_pigtail_config, pigtail_configs].join("\n\n")
|
|
108
|
+
# end.gsub(/\n{3,}/, "\n\n") # More than two newlines becomes just two.
|
|
109
|
+
# end
|
|
110
|
+
|
|
111
|
+
# def prepare(contents)
|
|
112
|
+
# # Strip n lines from the top of the file as specified by the :cut option.
|
|
113
|
+
# # Use split with a -1 limit option to ensure the join is able to rebuild
|
|
114
|
+
# # the file with all of the original seperators in-tact.
|
|
115
|
+
# stripped_contents = contents.split($/,-1)[@options[:cut]..-1].join($/)
|
|
116
|
+
#
|
|
117
|
+
# # Some pigtail config implementations require all non-comment lines to be newline-
|
|
118
|
+
# # terminated. (issue #95) Strip all newlines and replace with the default
|
|
119
|
+
# # platform record seperator ($/)
|
|
120
|
+
# stripped_contents.gsub!(/\s+$/, $/)
|
|
121
|
+
# end
|
|
122
|
+
|
|
123
|
+
def comment_base
|
|
124
|
+
"Pigtail generated configures for: #{@options[:identifier]}"
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def comment_open
|
|
128
|
+
"# Begin #{comment_base}"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def comment_close
|
|
132
|
+
"# End #{comment_base}"
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# require 'shellwords'
|
|
2
|
+
|
|
3
|
+
module Pigtail
|
|
4
|
+
class Config
|
|
5
|
+
|
|
6
|
+
def initialize(options = {})
|
|
7
|
+
@options = options
|
|
8
|
+
@template = options.delete(:template)
|
|
9
|
+
@config_template = options.delete(:config_template) || ":config"
|
|
10
|
+
# @options[:environment_variable] ||= "RAILS_ENV"
|
|
11
|
+
# @options[:environment] ||= :production
|
|
12
|
+
# @options[:path] = Shellwords.shellescape(@options[:path] || Pigtail.path)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def output
|
|
16
|
+
config = process_template(@template, @options)
|
|
17
|
+
out = process_template(@config_template, @options.merge(:config => config))
|
|
18
|
+
out.gsub(/%/, '\%')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
def process_template(template, options)
|
|
24
|
+
template.to_s.gsub(/:\w+/) do |key|
|
|
25
|
+
before_and_after = [$`[-1..-1], $'[0..0]]
|
|
26
|
+
option = options[key.sub(':', '').to_sym] || key
|
|
27
|
+
|
|
28
|
+
if before_and_after.all? { |c| c == "'" }
|
|
29
|
+
escape_single_quotes(option)
|
|
30
|
+
elsif before_and_after.all? { |c| c == '"' }
|
|
31
|
+
escape_double_quotes(option)
|
|
32
|
+
else
|
|
33
|
+
option
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
# end.gsub(/\s+/m, " ").strip
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def escape_single_quotes(str)
|
|
40
|
+
str.gsub(/'/) { "'\\''" }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def escape_double_quotes(str)
|
|
44
|
+
str.gsub(/"/) { '\"' }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
module Pigtail
|
|
2
|
+
class Configs
|
|
3
|
+
|
|
4
|
+
def initialize(options)
|
|
5
|
+
@configs, @set_variables, @pre_set_variables = {}, {}, {}, {}
|
|
6
|
+
|
|
7
|
+
if options.is_a? String
|
|
8
|
+
options = { :string => options }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
pre_set(options[:set])
|
|
12
|
+
|
|
13
|
+
# setup_file = File.expand_path('../setup.rb', __FILE__)
|
|
14
|
+
# setup = File.read(setup_file)
|
|
15
|
+
pigtail_config =
|
|
16
|
+
if options[:string]
|
|
17
|
+
options[:string]
|
|
18
|
+
elsif options[:file]
|
|
19
|
+
File.read(options[:file])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# instance_eval(setup, setup_file)
|
|
23
|
+
instance_eval(pigtail_config, options[:file] || '<eval>')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def set(variable, value)
|
|
27
|
+
variable = variable.to_sym
|
|
28
|
+
return if @pre_set_variables[variable]
|
|
29
|
+
|
|
30
|
+
instance_variable_set("@#{variable}".to_sym, value)
|
|
31
|
+
self.class.send(:attr_reader, variable.to_sym)
|
|
32
|
+
@set_variables[variable] = value
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def to(path, options = {})
|
|
36
|
+
@current_path_scope = path
|
|
37
|
+
@options = options
|
|
38
|
+
yield
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def config_type(name, template)
|
|
42
|
+
singleton_class_shim.class_eval do
|
|
43
|
+
define_method(name) do |task, *args|
|
|
44
|
+
options = { :task => task, :template => template }
|
|
45
|
+
options.merge!(args[0]) if args[0].is_a? Hash
|
|
46
|
+
|
|
47
|
+
@configs[@current_path_scope] ||= []
|
|
48
|
+
@configs[@current_path_scope] << Pigtail::Config.new(@options.merge(@set_variables).merge(options))
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def generate_configs_output
|
|
54
|
+
output_configs
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
# The Object#singleton_class method only became available in MRI 1.9.2, so
|
|
60
|
+
# we need this to maintain 1.8 compatibility. Once 1.8 support is dropped,
|
|
61
|
+
# this can be removed
|
|
62
|
+
def singleton_class_shim
|
|
63
|
+
if self.respond_to?(:singleton_class)
|
|
64
|
+
singleton_class
|
|
65
|
+
else
|
|
66
|
+
class << self; self; end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
# Takes a string like: "variable1=something&variable2=somethingelse"
|
|
72
|
+
# and breaks it into variable/value pairs. Used for setting variables at runtime from the command line.
|
|
73
|
+
# Only works for setting values as strings.
|
|
74
|
+
#
|
|
75
|
+
def pre_set(variable_string = nil)
|
|
76
|
+
return if variable_string.nil? || variable_string == ""
|
|
77
|
+
|
|
78
|
+
pairs = variable_string.split('&')
|
|
79
|
+
pairs.each do |pair|
|
|
80
|
+
next unless pair.index('=')
|
|
81
|
+
variable, value = *pair.split('=')
|
|
82
|
+
unless variable.nil? || variable == "" || value.nil? || value == ""
|
|
83
|
+
variable = variable.strip.to_sym
|
|
84
|
+
set(variable, value.strip)
|
|
85
|
+
@pre_set_variables[variable] = value
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
#
|
|
91
|
+
# Takes the standard config output that Pigtail generates and finds
|
|
92
|
+
# similar entries that can be combined. For example: If a configure should run
|
|
93
|
+
# at "/foo/bar" and "/foo/baz", instead of creating two configures this method combines
|
|
94
|
+
# them into one that runs at the 2nd, 3rd and 4th directory.
|
|
95
|
+
#
|
|
96
|
+
def combine(entries)
|
|
97
|
+
entries.map! { |entry| entry.split(/ +/, 6) }
|
|
98
|
+
0.upto(4) do |f|
|
|
99
|
+
(entries.length-1).downto(1) do |i|
|
|
100
|
+
next if entries[i][f] == '*'
|
|
101
|
+
comparison = entries[i][0...f] + entries[i][f+1..-1]
|
|
102
|
+
(i-1).downto(0) do |j|
|
|
103
|
+
next if entries[j][f] == '*'
|
|
104
|
+
if comparison == entries[j][0...f] + entries[j][f+1..-1]
|
|
105
|
+
entries[j][f] += ',' + entries[i][f]
|
|
106
|
+
entries.delete_at(i)
|
|
107
|
+
break
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
entries.map { |entry| entry.join(' ') }
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def output_configs
|
|
117
|
+
return if @configs.empty?
|
|
118
|
+
|
|
119
|
+
@output_configs = []
|
|
120
|
+
|
|
121
|
+
@configs.each do |paths, configs|
|
|
122
|
+
configs.each do |config|
|
|
123
|
+
Pigtail::Output::Config.output(paths, config) do |pigtail_config|
|
|
124
|
+
@output_configs << pigtail_config
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
return @output_configs
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Pigtail
|
|
2
|
+
module Output
|
|
3
|
+
class Config
|
|
4
|
+
attr_accessor :path, :configure
|
|
5
|
+
|
|
6
|
+
def initialize(path = nil, configure = nil)
|
|
7
|
+
@path = path
|
|
8
|
+
@configure = configure
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.enumerate(item)
|
|
12
|
+
if item and item.is_a?(String)
|
|
13
|
+
items = item.split(',')
|
|
14
|
+
else
|
|
15
|
+
items = item
|
|
16
|
+
items = [items] unless items and items.respond_to?(:each)
|
|
17
|
+
end
|
|
18
|
+
items
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.output(paths, config)
|
|
22
|
+
enumerate(paths).each do |path|
|
|
23
|
+
yield new(path, config.output).output
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def output
|
|
28
|
+
{ path: @path, configure: @configure }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Environment variable defaults to RAILS_ENV
|
|
2
|
+
set :environment_variable, "RAILS_ENV"
|
|
3
|
+
# Environment defaults to production
|
|
4
|
+
set :environment, "production"
|
|
5
|
+
# Path defaults to the directory `pigtail` was run from
|
|
6
|
+
set :path, Pigtail.path
|
|
7
|
+
|
|
8
|
+
# All configs are wrapped in this template.
|
|
9
|
+
set :config_template, ":config"
|
|
10
|
+
|
|
11
|
+
config_type :command, ":task"
|
data/lib/pigtail.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'pigtail/configs'
|
|
2
|
+
require 'pigtail/config'
|
|
3
|
+
require 'pigtail/command_line'
|
|
4
|
+
require 'pigtail/output_config'
|
|
5
|
+
require 'pigtail/version'
|
|
6
|
+
|
|
7
|
+
module Pigtail
|
|
8
|
+
def self.configs(options)
|
|
9
|
+
Pigtail::Configs.new(options).generate_configs_output
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.path
|
|
13
|
+
Dir.pwd
|
|
14
|
+
end
|
|
15
|
+
end
|
data/pigtail.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
+
|
|
3
|
+
require "pigtail/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "pigtail"
|
|
7
|
+
s.version = Pigtail::VERSION
|
|
8
|
+
s.authors = ["Nab Inno"]
|
|
9
|
+
s.email = ["nab@blahfe.com"]
|
|
10
|
+
s.homepage = "https://github.com/nabinno/pigtail"
|
|
11
|
+
s.summary = %q{Configs in ruby.}
|
|
12
|
+
s.description = %q{Clean ruby syntax for writing and deploying configs.}
|
|
13
|
+
s.license = "MIT"
|
|
14
|
+
|
|
15
|
+
s.files = Dir["{bin,lib,test}/**/*",
|
|
16
|
+
"Gemfile", "MIT-LICENSE", "README.md", "Rakefile", "pigtail.gemspec"]
|
|
17
|
+
s.test_files = Dir["test/{functional,unit}/*"]
|
|
18
|
+
s.executables = Dir["bin/*"].map{ |f| File.basename(f) }
|
|
19
|
+
s.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
s.add_development_dependency "bundler", "~> 1.9"
|
|
22
|
+
s.add_development_dependency 'mocha', '~> 0.9', '>= 0.9.5'
|
|
23
|
+
s.add_development_dependency 'rake', '~> 0'
|
|
24
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class OutputDefinedConfigTest < Pigtail::TestCase
|
|
4
|
+
test "defined config with a :task" do
|
|
5
|
+
output = Pigtail.configs \
|
|
6
|
+
<<-file
|
|
7
|
+
set :config_template, nil
|
|
8
|
+
config_type :some_config, "before :task after"
|
|
9
|
+
to "/foo/bar" do
|
|
10
|
+
some_config "during"
|
|
11
|
+
end
|
|
12
|
+
file
|
|
13
|
+
|
|
14
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after" }], output)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "defined config with a :task and some options" do
|
|
18
|
+
output = Pigtail.configs \
|
|
19
|
+
<<-file
|
|
20
|
+
set :config_template, nil
|
|
21
|
+
config_type :some_config, "before :task after :option1 :option2"
|
|
22
|
+
to "/foo/bar" do
|
|
23
|
+
some_config "during", :option1 => 'happy', :option2 => 'birthday'
|
|
24
|
+
end
|
|
25
|
+
file
|
|
26
|
+
|
|
27
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after happy birthday" }], output)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test "defined config with a :task and an option where the option is set globally" do
|
|
31
|
+
output = Pigtail.configs \
|
|
32
|
+
<<-file
|
|
33
|
+
set :config_template, nil
|
|
34
|
+
config_type :some_config, "before :task after :option1"
|
|
35
|
+
set :option1, 'happy'
|
|
36
|
+
to "/foo/bar" do
|
|
37
|
+
some_config "during"
|
|
38
|
+
end
|
|
39
|
+
file
|
|
40
|
+
|
|
41
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after happy" }], output)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
test "defined config with a :task and an option where the option is set globally and locally" do
|
|
45
|
+
output = Pigtail.configs \
|
|
46
|
+
<<-file
|
|
47
|
+
set :config_template, nil
|
|
48
|
+
config_type :some_config, "before :task after :option1"
|
|
49
|
+
set :option1, 'global'
|
|
50
|
+
to "/foo/bar" do
|
|
51
|
+
some_config "during", :option1 => 'local'
|
|
52
|
+
end
|
|
53
|
+
file
|
|
54
|
+
|
|
55
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after local" }], output)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
test "defined config with a :task and an option that is not set" do
|
|
59
|
+
output = Pigtail.configs \
|
|
60
|
+
<<-file
|
|
61
|
+
set :config_template, nil
|
|
62
|
+
config_type :some_config, "before :task after :option1"
|
|
63
|
+
to "/foo/bar" do
|
|
64
|
+
some_config "during", :option2 => 'happy'
|
|
65
|
+
end
|
|
66
|
+
file
|
|
67
|
+
|
|
68
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after :option1" }], output)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
test "defined config that uses a :path where none is explicitly set" do
|
|
72
|
+
Pigtail.stubs(:path).returns('/my/path')
|
|
73
|
+
|
|
74
|
+
output = Pigtail.configs \
|
|
75
|
+
<<-file
|
|
76
|
+
set :config_template, nil
|
|
77
|
+
config_type :some_config, "cd :path && :task"
|
|
78
|
+
to "/foo/bar" do
|
|
79
|
+
some_config 'blahblah'
|
|
80
|
+
end
|
|
81
|
+
file
|
|
82
|
+
|
|
83
|
+
assert_equal([{ path: foobar_directory, configure: %( cd /my/path && blahblah) }], output)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class CommandLineWriteTest < Pigtail::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
File.expects(:exists?).with('config/pigtail.rb').returns(true)
|
|
6
|
+
@command = Pigtail::CommandLine.new({ :write => true, :identifier => 'My identifier' })
|
|
7
|
+
@configures = { path: "#{foobar_directory}", configure: "/my/command" }
|
|
8
|
+
Pigtail.expects(:configs).returns(@configures)
|
|
9
|
+
end
|
|
10
|
+
should "output the pigtail config with identifier blocks" do
|
|
11
|
+
output = @configures[:configure]
|
|
12
|
+
assert_equal output, @command.send(:pigtail_configs)[:configure]
|
|
13
|
+
end
|
|
14
|
+
should "write the crontab when run" do
|
|
15
|
+
@command.expects(:write_pigtail_config).returns(true)
|
|
16
|
+
assert @command.run
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class ConfigTypeWithSetOptionTest < Pigtail::TestCase
|
|
21
|
+
setup do
|
|
22
|
+
@output = Pigtail.configs :string => \
|
|
23
|
+
<<-file
|
|
24
|
+
yaml = <<-YAML
|
|
25
|
+
- global:
|
|
26
|
+
env: :env
|
|
27
|
+
path: /foo/baz
|
|
28
|
+
YAML
|
|
29
|
+
config_type :yaml, yaml
|
|
30
|
+
to "/foo/bar" do
|
|
31
|
+
yaml "", { env: "ENV" }
|
|
32
|
+
end
|
|
33
|
+
file
|
|
34
|
+
end
|
|
35
|
+
should "output the runner using the override environment" do
|
|
36
|
+
assert_equal([{ path: foobar_directory, configure: %(- global:\n env: ENV\n path: /foo/baz\n) }], @output)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class OutputDefinedConfigTest < Pigtail::TestCase
|
|
4
|
+
test "defined config with a :task" do
|
|
5
|
+
output = Pigtail.configs \
|
|
6
|
+
<<-file
|
|
7
|
+
set :config_template, nil
|
|
8
|
+
config_type :some_config, "before :task after"
|
|
9
|
+
to "/foo/bar" do
|
|
10
|
+
some_config "during"
|
|
11
|
+
end
|
|
12
|
+
file
|
|
13
|
+
|
|
14
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after" }], output)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "defined config with a :task and some options" do
|
|
18
|
+
output = Pigtail.configs \
|
|
19
|
+
<<-file
|
|
20
|
+
set :config_template, nil
|
|
21
|
+
config_type :some_config, "before :task after :option1 :option2"
|
|
22
|
+
to "/foo/bar" do
|
|
23
|
+
some_config "during", :option1 => 'happy', :option2 => 'birthday'
|
|
24
|
+
end
|
|
25
|
+
file
|
|
26
|
+
|
|
27
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after happy birthday" }], output)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test "defined config with a :task and an option where the option is set globally" do
|
|
31
|
+
output = Pigtail.configs \
|
|
32
|
+
<<-file
|
|
33
|
+
set :config_template, nil
|
|
34
|
+
config_type :some_config, "before :task after :option1"
|
|
35
|
+
set :option1, 'happy'
|
|
36
|
+
to "/foo/bar" do
|
|
37
|
+
some_config "during"
|
|
38
|
+
end
|
|
39
|
+
file
|
|
40
|
+
|
|
41
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after happy" }], output)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
test "defined config with a :task and an option where the option is set globally and locally" do
|
|
45
|
+
output = Pigtail.configs \
|
|
46
|
+
<<-file
|
|
47
|
+
set :config_template, nil
|
|
48
|
+
config_type :some_config, "before :task after :option1"
|
|
49
|
+
set :option1, 'global'
|
|
50
|
+
to "/foo/bar" do
|
|
51
|
+
some_config "during", :option1 => 'local'
|
|
52
|
+
end
|
|
53
|
+
file
|
|
54
|
+
|
|
55
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after local" }], output)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
test "defined config with a :task and an option that is not set" do
|
|
59
|
+
output = Pigtail.configs \
|
|
60
|
+
<<-file
|
|
61
|
+
set :config_template, nil
|
|
62
|
+
config_type :some_config, "before :task after :option1"
|
|
63
|
+
to "/foo/bar" do
|
|
64
|
+
some_config "during", :option2 => 'happy'
|
|
65
|
+
end
|
|
66
|
+
file
|
|
67
|
+
|
|
68
|
+
assert_equal([{ path: "/foo/bar", configure: "before during after :option1" }], output)
|
|
69
|
+
end
|
|
70
|
+
end
|
data/test/test_case.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Pigtail
|
|
2
|
+
begin
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
begin
|
|
5
|
+
# 2.0.0
|
|
6
|
+
class TestCase < MiniTest::Test; end
|
|
7
|
+
rescue NameError
|
|
8
|
+
# 1.9.3
|
|
9
|
+
class TestCase < MiniTest::Unit::TestCase; end
|
|
10
|
+
end
|
|
11
|
+
rescue LoadError
|
|
12
|
+
# 1.8.7
|
|
13
|
+
require 'test/unit'
|
|
14
|
+
class TestCase < Test::Unit::TestCase
|
|
15
|
+
def default_test; end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class TestCase
|
|
20
|
+
class << self
|
|
21
|
+
def setup(&block)
|
|
22
|
+
define_method(:setup) do
|
|
23
|
+
super()
|
|
24
|
+
instance_eval(&block)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test(name, &block)
|
|
29
|
+
define_method("test_#{name}".to_sym, &block)
|
|
30
|
+
end
|
|
31
|
+
alias should test
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def assert_no_match(regexp, string)
|
|
35
|
+
message = "<#{regexp}> expected to not match\n<#{string}>"
|
|
36
|
+
assert regexp !~ string, message
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'pigtail'
|
|
2
|
+
require 'test_case'
|
|
3
|
+
require 'mocha/setup'
|
|
4
|
+
|
|
5
|
+
module Pigtail::TestHelpers
|
|
6
|
+
protected
|
|
7
|
+
def new_config(options={})
|
|
8
|
+
Pigtail::Config.new(options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def foobar_directory
|
|
12
|
+
"/foo/bar"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Pigtail::TestCase.send(:include, Pigtail::TestHelpers)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ConfigTest < Pigtail::TestCase
|
|
4
|
+
should "substitute the :task when #output is called" do
|
|
5
|
+
config = new_config(:template => ":task", :task => 'abc123')
|
|
6
|
+
assert_equal 'abc123', config.output
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
should "substitute the :path when #output is called" do
|
|
10
|
+
assert_equal 'foo', new_config(:template => ':path', :path => 'foo').output
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
should "not substitute parameters for which no value is set" do
|
|
14
|
+
assert_equal 'Hello :world', new_config(:template => ':matching :world', :matching => 'Hello').output
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
should "escape percent signs" do
|
|
18
|
+
config = new_config(
|
|
19
|
+
:template => "before :foo after",
|
|
20
|
+
:foo => "percent -> % <- percent"
|
|
21
|
+
)
|
|
22
|
+
assert_equal %q(before percent -> \% <- percent after), config.output
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
should "assume percent signs are not already escaped" do
|
|
26
|
+
config = new_config(
|
|
27
|
+
:template => "before :foo after",
|
|
28
|
+
:foo => %q(percent preceded by a backslash -> \% <-)
|
|
29
|
+
)
|
|
30
|
+
assert_equal %q(before percent preceded by a backslash -> \\\% <- after), config.output
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class ConfigWithQuotesTest < Pigtail::TestCase
|
|
35
|
+
should "output the :task if it's in single quotes" do
|
|
36
|
+
config = new_config(:template => "':task'", :task => 'abc123')
|
|
37
|
+
assert_equal %q('abc123'), config.output
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
should "output the :task if it's in double quotes" do
|
|
41
|
+
config = new_config(:template => '":task"', :task => 'abc123')
|
|
42
|
+
assert_equal %q("abc123"), config.output
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
should "output escaped single quotes in when it's wrapped in them" do
|
|
46
|
+
config = new_config(
|
|
47
|
+
:template => "before ':foo' after",
|
|
48
|
+
:foo => "quote -> ' <- quote"
|
|
49
|
+
)
|
|
50
|
+
assert_equal %q(before 'quote -> '\'' <- quote' after), config.output
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should "output escaped double quotes when it's wrapped in them" do
|
|
54
|
+
config = new_config(
|
|
55
|
+
:template => 'before ":foo" after',
|
|
56
|
+
:foo => 'quote -> " <- quote'
|
|
57
|
+
)
|
|
58
|
+
assert_equal %q(before "quote -> \" <- quote" after), config.output
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class ConfigWithConfigTemplateTest < Pigtail::TestCase
|
|
63
|
+
should "use the config template" do
|
|
64
|
+
config = new_config(:template => ':task', :task => 'abc123', :config_template => 'left :config right')
|
|
65
|
+
assert_equal 'left abc123 right', config.output
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
should "reuse parameter in the config template" do
|
|
69
|
+
config = new_config(:template => ':path :task', :path => 'path', :task => "abc123", :config_template => ':path left :config right')
|
|
70
|
+
assert_equal 'path left path abc123 right', config.output
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
should "escape single quotes" do
|
|
74
|
+
config = new_config(:template => "before ':task' after", :task => "quote -> ' <- quote", :config_template => "left ':config' right")
|
|
75
|
+
assert_equal %q(left 'before '\''quote -> '\\''\\'\\'''\\'' <- quote'\'' after' right), config.output
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
should "escape double quotes" do
|
|
79
|
+
config = new_config(:template => 'before ":task" after', :task => 'quote -> " <- quote', :config_template => 'left ":config" right')
|
|
80
|
+
assert_equal %q(left "before \"quote -> \\\" <- quote\" after" right), config.output
|
|
81
|
+
end
|
|
82
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pigtail
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.17
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nab Inno
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.9'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.9'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: mocha
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.9'
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: 0.9.5
|
|
37
|
+
type: :development
|
|
38
|
+
prerelease: false
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - "~>"
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0.9'
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.9.5
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: rake
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
description: Clean ruby syntax for writing and deploying configs.
|
|
62
|
+
email:
|
|
63
|
+
- nab@blahfe.com
|
|
64
|
+
executables:
|
|
65
|
+
- pigtail
|
|
66
|
+
- pigtailize
|
|
67
|
+
extensions: []
|
|
68
|
+
extra_rdoc_files: []
|
|
69
|
+
files:
|
|
70
|
+
- Gemfile
|
|
71
|
+
- MIT-LICENSE
|
|
72
|
+
- README.md
|
|
73
|
+
- Rakefile
|
|
74
|
+
- bin/pigtail
|
|
75
|
+
- bin/pigtailize
|
|
76
|
+
- lib/pigtail.rb
|
|
77
|
+
- lib/pigtail/command_line.rb
|
|
78
|
+
- lib/pigtail/config.rb
|
|
79
|
+
- lib/pigtail/configs.rb
|
|
80
|
+
- lib/pigtail/output_config.rb
|
|
81
|
+
- lib/pigtail/setup.rb
|
|
82
|
+
- lib/pigtail/version.rb
|
|
83
|
+
- pigtail.gemspec
|
|
84
|
+
- test/functional/#setup_test.rb#
|
|
85
|
+
- test/functional/command_line_test.rb
|
|
86
|
+
- test/functional/setup_test.rb
|
|
87
|
+
- test/pigtail_test.rb
|
|
88
|
+
- test/test_case.rb
|
|
89
|
+
- test/test_helper.rb
|
|
90
|
+
- test/unit/config_test.rb
|
|
91
|
+
- test/unit/output_config_test.rb
|
|
92
|
+
homepage: https://github.com/nabinno/pigtail
|
|
93
|
+
licenses:
|
|
94
|
+
- MIT
|
|
95
|
+
metadata: {}
|
|
96
|
+
post_install_message:
|
|
97
|
+
rdoc_options: []
|
|
98
|
+
require_paths:
|
|
99
|
+
- lib
|
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
requirements: []
|
|
111
|
+
rubyforge_project:
|
|
112
|
+
rubygems_version: 2.4.5
|
|
113
|
+
signing_key:
|
|
114
|
+
specification_version: 4
|
|
115
|
+
summary: Configs in ruby.
|
|
116
|
+
test_files:
|
|
117
|
+
- test/functional/command_line_test.rb
|
|
118
|
+
- test/functional/#setup_test.rb#
|
|
119
|
+
- test/functional/setup_test.rb
|
|
120
|
+
- test/unit/output_config_test.rb
|
|
121
|
+
- test/unit/config_test.rb
|