Thin_Upstart 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -8
- data/bin/Thin_Upstart +24 -4
- data/lib/Thin_Upstart.rb +6 -3
- data/lib/Thin_Upstart/version.rb +1 -1
- data/spec/templates/custom/custom.conf +4 -0
- data/spec/templates/missing/missing.conf +4 -0
- data/spec/tests/bin.rb +7 -0
- data/spec/tests/mustache.rb +24 -0
- metadata +3 -1
data/README.md
CHANGED
@@ -39,6 +39,7 @@ Usage: Ruby
|
|
39
39
|
o.templates "./templates/*.conf" # file glob
|
40
40
|
o.output "./upstart"
|
41
41
|
o.yml "config/thin.yml"
|
42
|
+
o.kv Hash[] # Custom key/value for your mustache templates.
|
42
43
|
}
|
43
44
|
|
44
45
|
If you want to delete files generated by Thin\_Upstart, use:
|
@@ -70,18 +71,18 @@ Usage: Mustache Template
|
|
70
71
|
-----
|
71
72
|
In your Mustache templates, you have access to the following values:
|
72
73
|
|
73
|
-
*
|
74
|
-
*
|
75
|
-
*
|
76
|
-
*
|
77
|
-
*
|
78
|
-
*
|
74
|
+
* **name:** Name of app group: e.g. My-Web-Apps
|
75
|
+
* **app:** Name of current app: e.g. Blog
|
76
|
+
* **yml:** Relative path from current app directory to .yml file
|
77
|
+
* **app\_path:** Full path to app.
|
78
|
+
* **yml\_path:** Full path to .yml file.
|
79
|
+
* **apps\_dir:** Full path to directory of apps.
|
79
80
|
|
80
81
|
You can use Mustache values in the file names of the templates.
|
81
82
|
For example:
|
82
83
|
|
83
|
-
* my/template/dir
|
84
|
-
* my/template/dir
|
84
|
+
* my/template/dir/**{{name}}**.conf
|
85
|
+
* my/template/dir/**{{name}}**-**{{app}}**.conf
|
85
86
|
|
86
87
|
The files are generated are:
|
87
88
|
|
data/bin/Thin_Upstart
CHANGED
@@ -12,6 +12,7 @@ h = Hash[
|
|
12
12
|
:apps => "Path to dir containing apps.",
|
13
13
|
:templates => "File glob for templates: e.g. \"./templates/*.conf\"",
|
14
14
|
:output => "Output directory.",
|
15
|
+
:kv => %@ Additional values for Mustache: e.g. --kv " k1 => v1 , k2 => v2 " @,
|
15
16
|
:trash => "Dir to trash. All other arguments are ignored."
|
16
17
|
]
|
17
18
|
|
@@ -21,18 +22,37 @@ opts = Trollop::options do
|
|
21
22
|
}
|
22
23
|
end
|
23
24
|
|
25
|
+
def string_to_hash orig
|
26
|
+
temp = orig.split(',').map { |pair| pair.split("=>") }
|
27
|
+
unless temp.map { |pair| pair.size }.uniq == [2]
|
28
|
+
raise ArgumentError, "Invalid format for hash: #{orig}"
|
29
|
+
end
|
30
|
+
|
31
|
+
temp.inject(Hash[]) { |memo, pair|
|
32
|
+
memo[pair.first.strip] = pair.last.strip
|
33
|
+
memo
|
34
|
+
}
|
35
|
+
end # ==== string_to_hash
|
36
|
+
|
24
37
|
if opts[:trash_given]
|
38
|
+
|
25
39
|
files = Thin_Upstart.trash opts[:trash]
|
26
40
|
files.each { |f|
|
27
41
|
puts "deleted: #{f}"
|
28
42
|
}
|
43
|
+
|
29
44
|
else
|
45
|
+
|
30
46
|
files = Thin_Upstart { |o|
|
31
47
|
h.each { |k, desc|
|
32
|
-
|
48
|
+
next unless opts[:"#{k}_given"]
|
49
|
+
|
50
|
+
(opts[k] = string_to_hash(opts[k])) if [ :kv, 'kv' ].include?(k)
|
51
|
+
o.send(k, opts[k])
|
33
52
|
}
|
34
53
|
}
|
35
|
-
|
36
|
-
|
37
|
-
|
54
|
+
|
55
|
+
files.each { |f|
|
56
|
+
puts "created: #{f}"
|
57
|
+
}
|
38
58
|
end
|
data/lib/Thin_Upstart.rb
CHANGED
@@ -2,6 +2,8 @@ require 'Thin_Upstart/version'
|
|
2
2
|
require 'Exit_Zero'
|
3
3
|
require 'mustache'
|
4
4
|
|
5
|
+
Mustache.raise_on_context_miss = true
|
6
|
+
|
5
7
|
def Thin_Upstart
|
6
8
|
o = Thin_Upstart.new
|
7
9
|
yield o
|
@@ -34,6 +36,7 @@ class Thin_Upstart
|
|
34
36
|
templates "./templates/*.conf"
|
35
37
|
output "./upstart"
|
36
38
|
yml "thin.yml"
|
39
|
+
kv Hash[]
|
37
40
|
yield(self) if block_given?
|
38
41
|
end
|
39
42
|
|
@@ -63,7 +66,7 @@ class Thin_Upstart
|
|
63
66
|
app_list << app
|
64
67
|
|
65
68
|
yml = yml_path.sub( File.join(app_path, '/'), '')
|
66
|
-
|
69
|
+
|
67
70
|
vals = remove_last_slash Hash[
|
68
71
|
:name => name,
|
69
72
|
:app => app,
|
@@ -71,7 +74,7 @@ class Thin_Upstart
|
|
71
74
|
:yml => yml,
|
72
75
|
:yml_path => yml_path,
|
73
76
|
:apps_dir => File.expand_path(apps)
|
74
|
-
]
|
77
|
+
].merge(kv || {} )
|
75
78
|
|
76
79
|
tmpls.each { |file|
|
77
80
|
temp_path = Mustache.render(file, vals)
|
@@ -99,7 +102,7 @@ class Thin_Upstart
|
|
99
102
|
end
|
100
103
|
end
|
101
104
|
|
102
|
-
%w{ name yml }.each { |attr|
|
105
|
+
%w{ name yml kv }.each { |attr|
|
103
106
|
|
104
107
|
eval %~
|
105
108
|
def #{attr} *args
|
data/lib/Thin_Upstart/version.rb
CHANGED
data/spec/tests/bin.rb
CHANGED
@@ -58,6 +58,13 @@ describe "bin: Thin_Upstart" do
|
|
58
58
|
should_mustache "name", "My-Apps", "new-upstart/My-Apps-Hi.conf"
|
59
59
|
}
|
60
60
|
end
|
61
|
+
|
62
|
+
it "accepts --kv" do
|
63
|
+
chdir {
|
64
|
+
bin %@ --templates templates/custom/*.conf --kv " custom_1 => 1 , custom_2 => c2"@
|
65
|
+
should_mustache "custom_2", "c2", "upstart/custom.conf"
|
66
|
+
}
|
67
|
+
end
|
61
68
|
|
62
69
|
end # === bin: Thin_Upstart
|
63
70
|
|
data/spec/tests/mustache.rb
CHANGED
@@ -27,6 +27,30 @@ describe "Thin_Upstart Mustache values" do
|
|
27
27
|
chdir { should_mustache 'apps_dir', File.expand_path("./apps") }
|
28
28
|
end
|
29
29
|
|
30
|
+
it "sets custom values" do
|
31
|
+
chdir {
|
32
|
+
Thin_Upstart { |o|
|
33
|
+
o.name 'my-apps'
|
34
|
+
o.templates 'templates/custom/*.conf'
|
35
|
+
o.kv :custom_1=>"1", :custom_2=>"2"
|
36
|
+
}
|
37
|
+
should_mustache 'custom_1', '1', "upstart/custom.conf"
|
38
|
+
should_mustache 'custom_2', '2', "upstart/custom.conf"
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises error if Mustache templates uses unknown value" do
|
43
|
+
chdir {
|
44
|
+
lambda do
|
45
|
+
Thin_Upstart { |o|
|
46
|
+
o.name 'my-apps'
|
47
|
+
o.templates 'templates/missing/*.conf'
|
48
|
+
}
|
49
|
+
end.should.raise(Mustache::ContextMiss)
|
50
|
+
.message.should.match %r!Can't find custom_123 in !
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
30
54
|
end # === Thin_Upstart Mustache values
|
31
55
|
|
32
56
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Thin_Upstart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -144,6 +144,8 @@ files:
|
|
144
144
|
- lib/templates/{{name}}.conf
|
145
145
|
- spec/helper.rb
|
146
146
|
- spec/main.rb
|
147
|
+
- spec/templates/custom/custom.conf
|
148
|
+
- spec/templates/missing/missing.conf
|
147
149
|
- spec/templates/{{name}}-{{app}}.conf
|
148
150
|
- spec/templates/{{name}}.conf
|
149
151
|
- spec/tests/bin.rb
|