sous_chef 0.0.2 → 0.0.3
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/.gitignore +1 -0
- data/VERSION.yml +1 -1
- data/lib/sous_chef/resource/directory.rb +11 -1
- data/lib/sous_chef/resource/file.rb +5 -5
- data/spec/resource/directory_spec.rb +9 -1
- data/spec/resource/file_spec.rb +23 -0
- metadata +2 -2
data/.gitignore
CHANGED
data/VERSION.yml
CHANGED
@@ -5,6 +5,7 @@ module SousChef
|
|
5
5
|
|
6
6
|
def initialize(*args)
|
7
7
|
action :create
|
8
|
+
force false
|
8
9
|
super
|
9
10
|
end
|
10
11
|
|
@@ -20,6 +21,14 @@ module SousChef
|
|
20
21
|
set_or_return(:action, action && validate_action(action))
|
21
22
|
end
|
22
23
|
|
24
|
+
def force(forced)
|
25
|
+
@forced = forced
|
26
|
+
end
|
27
|
+
|
28
|
+
def forced?
|
29
|
+
@forced
|
30
|
+
end
|
31
|
+
|
23
32
|
def to_script
|
24
33
|
@script ||= begin
|
25
34
|
setup
|
@@ -34,7 +43,8 @@ module SousChef
|
|
34
43
|
end
|
35
44
|
|
36
45
|
def delete
|
37
|
-
|
46
|
+
cmd = forced?? 'rm -rf' : 'rmdir'
|
47
|
+
command %{#{cmd} #{escape_path(path)}}
|
38
48
|
end
|
39
49
|
|
40
50
|
def validate_action(action)
|
@@ -2,22 +2,22 @@ module SousChef
|
|
2
2
|
module Resource
|
3
3
|
class File < Directory
|
4
4
|
def content(content=nil)
|
5
|
-
set_or_return(:content, content)
|
5
|
+
set_or_return(:content, content && content.to_s)
|
6
6
|
end
|
7
7
|
|
8
8
|
protected
|
9
9
|
def escaped_content
|
10
|
-
content
|
10
|
+
content
|
11
11
|
end
|
12
12
|
|
13
13
|
def create
|
14
|
-
not_if file_exist_command
|
14
|
+
not_if file_exist_command unless forced?
|
15
15
|
command create_file_command
|
16
16
|
end
|
17
17
|
|
18
18
|
def delete
|
19
|
-
only_if file_exist_command
|
20
|
-
command "rm #{escape_path(path)}"
|
19
|
+
only_if file_exist_command unless forced?
|
20
|
+
command "rm #{'-f ' if forced?}#{escape_path(path)}"
|
21
21
|
end
|
22
22
|
|
23
23
|
def file_exist_command
|
@@ -40,7 +40,7 @@ describe SousChef::Resource::Directory do
|
|
40
40
|
}.should raise_error(ArgumentError)
|
41
41
|
end
|
42
42
|
|
43
|
-
it "sets the mode of the
|
43
|
+
it "sets the mode of the directory" do
|
44
44
|
@directory = resource("bin") do
|
45
45
|
mode 0600
|
46
46
|
end
|
@@ -50,4 +50,12 @@ mkdir -p bin
|
|
50
50
|
chmod 0600 bin
|
51
51
|
}.strip
|
52
52
|
end
|
53
|
+
|
54
|
+
it "force deletes the directory" do
|
55
|
+
directory = resource("bin") do
|
56
|
+
action :delete
|
57
|
+
force true
|
58
|
+
end
|
59
|
+
directory.to_script.should == %{rm -rf bin}
|
60
|
+
end
|
53
61
|
end
|
data/spec/resource/file_spec.rb
CHANGED
@@ -45,6 +45,18 @@ fi
|
|
45
45
|
}.strip
|
46
46
|
end
|
47
47
|
|
48
|
+
it "overwrites files with force true" do
|
49
|
+
@file = resource("note.txt") do
|
50
|
+
content %{new content}
|
51
|
+
force true
|
52
|
+
end
|
53
|
+
@file.to_script.should == %{
|
54
|
+
cat <<'SousChefHeredoc' > note.txt
|
55
|
+
new content
|
56
|
+
SousChefHeredoc
|
57
|
+
}.strip
|
58
|
+
end
|
59
|
+
|
48
60
|
it "handles single-quotes in the content" do
|
49
61
|
@file = resource("note.txt") do
|
50
62
|
content %{this is a 'note'}
|
@@ -155,4 +167,15 @@ if test -e note.txt; then
|
|
155
167
|
fi
|
156
168
|
}.strip
|
157
169
|
end
|
170
|
+
|
171
|
+
it "force deletes a file" do
|
172
|
+
@file = resource("note.txt") do
|
173
|
+
action :delete
|
174
|
+
force true
|
175
|
+
end
|
176
|
+
|
177
|
+
@file.to_script.should == %q{
|
178
|
+
rm -f note.txt
|
179
|
+
}.strip
|
180
|
+
end
|
158
181
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sous_chef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Emde
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-
|
13
|
+
date: 2010-03-03 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|