capistrano-file-resources 0.1.0 → 0.1.1
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.
- data/capistrano-file-resources.gemspec +1 -0
- data/lib/capistrano/configuration/resources/file_resources.rb +17 -6
- data/lib/capistrano/configuration/resources/file_resources/version.rb +1 -1
- data/test/centos6-64/run.sh +1 -1
- data/test/config/deploy.rb +41 -16
- data/test/precise64/run.sh +1 -1
- metadata +18 -2
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = Capistrano::Configuration::Resources::FileResources::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency("capistrano")
|
19
|
+
gem.add_dependency("mime-types")
|
19
20
|
gem.add_development_dependency("net-scp", "~> 1.0.4")
|
20
21
|
gem.add_development_dependency("net-ssh", "~> 2.2.2")
|
21
22
|
gem.add_development_dependency("vagrant", "~> 1.0.6")
|
@@ -1,26 +1,37 @@
|
|
1
1
|
require "capistrano/configuration/resources/file_resources/version"
|
2
2
|
require "capistrano/configuration"
|
3
3
|
require "erb"
|
4
|
+
require "mime/types"
|
4
5
|
|
5
6
|
module Capistrano
|
6
7
|
class Configuration
|
7
8
|
module Resources
|
8
9
|
module FileResources
|
9
10
|
def file(name, options={})
|
10
|
-
|
11
|
+
options = options.dup
|
12
|
+
path = ( options.delete(:path) || "." )
|
11
13
|
begin
|
12
|
-
File.read(File.join(path, name))
|
14
|
+
File.read(File.join(path, name), options)
|
13
15
|
rescue SystemCallError => error
|
14
16
|
abort("Could not render file resource - #{error}")
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
def template(name, options={})
|
19
|
-
path = options.fetch(:path, ".")
|
20
|
-
|
21
|
-
|
21
|
+
path = options.fetch(:path, "." )
|
22
|
+
if File.exist?(File.join(path, "#{name}.erb"))
|
23
|
+
name = "#{name}.erb"
|
24
|
+
else
|
25
|
+
types = MIME::Types.type_for(name)
|
26
|
+
if types.include?("text/html")
|
27
|
+
name_without_ext = File.basename(name, File.extname(name))
|
28
|
+
if File.exist?(File.join(path, "#{name_without_ext}.rhtml"))
|
29
|
+
name = "#{name_without_ext}.rhtml"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
22
33
|
begin
|
23
|
-
ERB.new(
|
34
|
+
ERB.new(file(name, options)).result(options.fetch(:binding, binding))
|
24
35
|
rescue StandardError => error
|
25
36
|
abort("Could not render template resource - #{error}")
|
26
37
|
end
|
data/test/centos6-64/run.sh
CHANGED
data/test/config/deploy.rb
CHANGED
@@ -16,21 +16,32 @@ role :db, "192.168.33.10", :primary => true
|
|
16
16
|
|
17
17
|
$LOAD_PATH.push(File.expand_path("../../lib", File.dirname(__FILE__)))
|
18
18
|
require "capistrano/configuration/resources/file_resources"
|
19
|
-
require "
|
19
|
+
require "tempfile"
|
20
20
|
|
21
21
|
task(:test_all) {
|
22
22
|
find_and_execute_task("test_default")
|
23
23
|
}
|
24
24
|
|
25
|
-
def assert_equals(x, y)
|
26
|
-
|
25
|
+
def assert_equals(x, y, options={})
|
26
|
+
begin
|
27
|
+
raise if x != y
|
28
|
+
rescue
|
29
|
+
logger.debug("assert_equals(#{x.dump}, #{y.dump}) failed.")
|
30
|
+
raise
|
31
|
+
end
|
27
32
|
end
|
28
33
|
|
29
|
-
def assert_raises(error)
|
34
|
+
def assert_raises(error, options={})
|
30
35
|
begin
|
31
36
|
yield
|
32
37
|
rescue error => e
|
33
|
-
|
38
|
+
raised = e
|
39
|
+
ensure
|
40
|
+
if raised
|
41
|
+
logger.debug("assert_raises(#{error}) expected exception: #{raised}")
|
42
|
+
else
|
43
|
+
raise("assert raises(#{error}) failed.")
|
44
|
+
end
|
34
45
|
end
|
35
46
|
end
|
36
47
|
|
@@ -54,42 +65,56 @@ namespace(:test_default) {
|
|
54
65
|
}
|
55
66
|
|
56
67
|
task(:test_file) {
|
57
|
-
run_locally("rm -
|
58
|
-
|
68
|
+
run_locally("rm -rf tmp; mkdir tmp")
|
69
|
+
File.write("tmp/foo", "foo")
|
70
|
+
assert_equals(file("foo", :path => "tmp"), "foo")
|
59
71
|
}
|
60
72
|
|
61
73
|
task(:test_missing_file) {
|
62
|
-
run_locally("rm -
|
74
|
+
run_locally("rm -rf tmp; mkdir tmp")
|
63
75
|
assert_raises(SystemExit) do
|
64
76
|
file("foo", :path => "tmp")
|
65
77
|
end
|
66
78
|
}
|
67
79
|
|
68
80
|
task(:test_file_with_suffix) {
|
69
|
-
run_locally("rm -
|
70
|
-
|
81
|
+
run_locally("rm -rf tmp; mkdir tmp")
|
82
|
+
File.write("tmp/foo", "foo")
|
83
|
+
File.write("tmp/foo.erb", "foo.erb")
|
84
|
+
assert_equals(file("foo", :path => "tmp"), "foo")
|
85
|
+
|
71
86
|
}
|
72
87
|
|
73
88
|
task(:test_template) {
|
74
|
-
run_locally("rm -
|
75
|
-
|
89
|
+
run_locally("rm -rf tmp; mkdir tmp")
|
90
|
+
File.write("tmp/bar", "bar")
|
91
|
+
assert_equals(template("bar", :path => "tmp"), "bar")
|
76
92
|
}
|
77
93
|
|
78
94
|
task(:test_missing_template) {
|
79
|
-
run_locally("rm -
|
95
|
+
run_locally("rm -rf tmp; mkdir tmp")
|
80
96
|
assert_raises(SystemExit) do
|
81
97
|
template("bar", :path => "tmp")
|
82
98
|
end
|
83
99
|
}
|
84
100
|
|
85
101
|
task(:test_template_with_suffix) {
|
86
|
-
run_locally("rm -
|
87
|
-
|
102
|
+
run_locally("rm -rf tmp; mkdir tmp")
|
103
|
+
File.write("tmp/bar", "bar")
|
104
|
+
File.write("tmp/bar.erb", "bar.erb")
|
105
|
+
assert_equals(template("bar", :path => "tmp"), "bar.erb")
|
106
|
+
}
|
107
|
+
|
108
|
+
task(:test_template_with_suffix_rhtml) {
|
109
|
+
run_locally("rm -rf tmp; mkdir tmp")
|
110
|
+
File.write("tmp/bar.rhtml", "bar.rhtml")
|
111
|
+
assert_equals(template("bar.html", :path => "tmp"), "bar.rhtml")
|
88
112
|
}
|
89
113
|
|
90
114
|
task(:test_template_rendering) {
|
115
|
+
run_locally("rm -rf tmp; mkdir tmp")
|
91
116
|
File.write("tmp/baz.erb", %q{<%= "baz" %>})
|
92
|
-
assert_equals(
|
117
|
+
assert_equals(template("baz", :path => "tmp"), "baz")
|
93
118
|
}
|
94
119
|
}
|
95
120
|
|
data/test/precise64/run.sh
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-file-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mime-types
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: net-scp
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|