files 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/files.rb +15 -16
- data/lib/files/version.rb +1 -1
- metadata +4 -4
data/lib/files.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require "files/version"
|
2
2
|
|
3
|
-
module Files
|
3
|
+
module Files
|
4
4
|
|
5
5
|
# class methods
|
6
|
-
|
6
|
+
|
7
7
|
def self.default_options level = 2
|
8
8
|
{:remove => true, :name => called_from(level)}
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.called_from level = 1
|
12
12
|
line = caller[level]
|
13
13
|
line.gsub!(/^.:/, '') # correct for leading Windows C:
|
14
14
|
File.basename line.split(':').first, ".rb"
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def self.create options = default_options, &block
|
18
18
|
require 'tmpdir'
|
19
19
|
require 'fileutils'
|
@@ -31,28 +31,27 @@ module Files
|
|
31
31
|
end
|
32
32
|
|
33
33
|
path = File.join(root, "#{name}_#{Time.now.to_i}_#{rand(1000)}")
|
34
|
-
d{path}
|
35
34
|
Files.new path, block, options
|
36
35
|
end
|
37
|
-
|
36
|
+
|
38
37
|
# mixin methods
|
39
38
|
def files options = ::Files.default_options # todo: block
|
40
39
|
@files ||= ::Files.create(options)
|
41
40
|
end
|
42
|
-
|
41
|
+
|
43
42
|
def file *args, &block
|
44
43
|
files.file *args, &block
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
def dir *args, &block
|
48
47
|
files.dir *args, &block
|
49
48
|
end
|
50
|
-
|
51
|
-
# concrete class for creating files and dirs under a temporary directory
|
49
|
+
|
50
|
+
# concrete class for creating files and dirs under a temporary directory
|
52
51
|
class Files
|
53
|
-
|
52
|
+
|
54
53
|
attr_reader :root
|
55
|
-
|
54
|
+
|
56
55
|
def initialize path, block, options
|
57
56
|
@root = path
|
58
57
|
@dirs = []
|
@@ -81,7 +80,7 @@ module Files
|
|
81
80
|
@dirs.pop
|
82
81
|
path
|
83
82
|
end
|
84
|
-
|
83
|
+
|
85
84
|
def file name, contents = "contents of #{name}"
|
86
85
|
if name.is_a? File
|
87
86
|
FileUtils.cp name.path, current
|
@@ -98,16 +97,16 @@ module Files
|
|
98
97
|
path
|
99
98
|
end
|
100
99
|
end
|
101
|
-
|
100
|
+
|
102
101
|
def remove
|
103
102
|
FileUtils.rm_rf(@root) if File.exists?(@root)
|
104
103
|
end
|
105
|
-
|
104
|
+
|
106
105
|
private
|
107
106
|
def current
|
108
107
|
File.join @root, *@dirs
|
109
108
|
end
|
110
|
-
|
109
|
+
|
111
110
|
end
|
112
111
|
end
|
113
112
|
|
data/lib/files/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.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: 2012-
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ever want to create a whole bunch of files at once? Like when you're
|
15
15
|
writing tests for a tool that processes files? The Files gem lets you cleanly specify
|
@@ -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: 1058874154212753118
|
49
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
segments:
|
56
56
|
- 0
|
57
|
-
hash:
|
57
|
+
hash: 1058874154212753118
|
58
58
|
requirements: []
|
59
59
|
rubyforge_project: files
|
60
60
|
rubygems_version: 1.8.24
|