files 0.0.3 → 0.0.4
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/lib/files.rb +6 -2
- data/lib/files/version.rb +1 -1
- data/test/files_test.rb +13 -0
- metadata +5 -5
data/lib/files.rb
CHANGED
@@ -38,24 +38,28 @@ module Files
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def dir name, &block
|
41
|
-
|
41
|
+
path = "#{current}/#{name}"
|
42
|
+
Dir.mkdir path
|
42
43
|
@dirs << name
|
43
44
|
instance_eval &block if block
|
44
45
|
@dirs.pop
|
46
|
+
path
|
45
47
|
end
|
46
48
|
|
47
49
|
def file name, contents = "contents of #{name}"
|
48
50
|
if name.is_a? File
|
49
51
|
FileUtils.cp name.path, current
|
52
|
+
# todo: return path
|
50
53
|
else
|
51
54
|
path = "#{current}/#{name}"
|
52
55
|
if contents.is_a? File
|
53
56
|
FileUtils.cp contents.path, path
|
54
57
|
else
|
55
|
-
File.open(path, "w") do |f|
|
58
|
+
file_path = File.open(path, "w") do |f|
|
56
59
|
f.write contents
|
57
60
|
end
|
58
61
|
end
|
62
|
+
path
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
data/lib/files/version.rb
CHANGED
data/test/files_test.rb
CHANGED
@@ -72,3 +72,16 @@ dir = Files do
|
|
72
72
|
end
|
73
73
|
assert { File.exist? "#{dir}/a" and File.directory? "#{dir}/a"}
|
74
74
|
|
75
|
+
|
76
|
+
# the file and dir methods return the path, suitable for saving into a predeclared local var
|
77
|
+
stuff = nil
|
78
|
+
hello = nil
|
79
|
+
dir = Files do
|
80
|
+
stuff = dir "stuff" do
|
81
|
+
hello = file "hello.txt"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
assert { stuff == "#{dir}/stuff" }
|
86
|
+
assert { hello == "#{dir}/stuff/hello.txt" }
|
87
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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: 2012-01-
|
12
|
+
date: 2012-01-14 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Sometimes you want to create a whole bunch of files at once, like when
|
15
15
|
you're testing a tool that processes a whole bunch of files. The Files gem lets
|
@@ -45,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
45
|
version: '0'
|
46
46
|
segments:
|
47
47
|
- 0
|
48
|
-
hash:
|
48
|
+
hash: -1672027565997057285
|
49
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
@@ -54,10 +54,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
segments:
|
56
56
|
- 0
|
57
|
-
hash:
|
57
|
+
hash: -1672027565997057285
|
58
58
|
requirements: []
|
59
59
|
rubyforge_project: files
|
60
|
-
rubygems_version: 1.8.
|
60
|
+
rubygems_version: 1.8.6
|
61
61
|
signing_key:
|
62
62
|
specification_version: 3
|
63
63
|
summary: a simple DSL for creating files and directories
|