fun_with_files 0.0.4 → 0.0.5
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/Gemfile +1 -0
- data/VERSION +1 -1
- data/lib/files/directory_builder.rb +179 -0
- data/lib/files/downloader.rb +62 -0
- data/lib/files/file_orderer.rb +44 -0
- data/lib/files/file_path.rb +48 -15
- data/lib/files/string_behavior.rb +24 -0
- data/lib/files/xdg_extensions.rb +7 -0
- data/lib/fun_with_files.rb +14 -2
- data/test/helper.rb +8 -0
- data/test/test_descent.rb +21 -0
- data/test/test_directory_builder.rb +136 -0
- data/test/test_file_path.rb +0 -2
- data/test/test_globbing.rb +0 -2
- data/test/test_loading.rb +0 -2
- data/test/test_root_path.rb +0 -2
- data/test/test_touching.rb +0 -2
- metadata +26 -3
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Files
|
3
|
+
|
4
|
+
# Describes a domain-specific language for creating and populating a
|
5
|
+
# directory of files.
|
6
|
+
class DirectoryBuilder
|
7
|
+
attr_accessor :current_path, :current_file
|
8
|
+
|
9
|
+
def initialize( path )
|
10
|
+
@paths = []
|
11
|
+
@current_path = path.fwf_filepath
|
12
|
+
make_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.create( path, &block )
|
16
|
+
builder = self.new( path )
|
17
|
+
yield builder if block_given?
|
18
|
+
builder
|
19
|
+
end
|
20
|
+
|
21
|
+
def dir( *args, &block )
|
22
|
+
descend( *args ) do
|
23
|
+
yield if block_given?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Beware: if block is given, the temp directory will be
|
28
|
+
#
|
29
|
+
def self.tmpdir( &block )
|
30
|
+
if block_given?
|
31
|
+
FilePath.tmpdir do |dir|
|
32
|
+
self.create( dir ) do |builder|
|
33
|
+
yield builder
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
self.create( FilePath.tmpdir )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Copies the given source file into a file in the current_path.
|
42
|
+
# If a dest_name is given, the new file will be given that name.
|
43
|
+
def copy( src_filepath, dst_name = nil )
|
44
|
+
dst_filepath = dst_name ? @current_path.join( dst_name ) : @current_path
|
45
|
+
FileUtils.copy( src_filepath, dst_filepath )
|
46
|
+
end
|
47
|
+
|
48
|
+
def file( name = nil, content = nil, &block )
|
49
|
+
# if name && content
|
50
|
+
# begin
|
51
|
+
# f = open_file( name )
|
52
|
+
# f << content
|
53
|
+
# ensure
|
54
|
+
# close_file
|
55
|
+
# end
|
56
|
+
if name
|
57
|
+
open_file( name )
|
58
|
+
@current_file << content if content
|
59
|
+
if block_given?
|
60
|
+
begin
|
61
|
+
yield @current_file
|
62
|
+
ensure
|
63
|
+
close_file
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
@current_file
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def current_file
|
72
|
+
@current_file ? FunWith::Files::FilePath.new( @current_file.path ) : nil
|
73
|
+
end
|
74
|
+
|
75
|
+
# if file not given, the result is appended to the current file.
|
76
|
+
def download( url, file = nil )
|
77
|
+
if file
|
78
|
+
if file.fwf_filepath.relative?
|
79
|
+
file = FunWith::Files::FilePath.new( @current_path, file )
|
80
|
+
end
|
81
|
+
|
82
|
+
File.open( file, "w" ) do |f|
|
83
|
+
download_to_target( url, f )
|
84
|
+
end
|
85
|
+
elsif @current_file
|
86
|
+
download_to_target( url, @current_file )
|
87
|
+
else
|
88
|
+
puts "No current file to append #{url} to."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
protected
|
93
|
+
def make_path
|
94
|
+
FileUtils.mkdir_p( @current_path ) unless @current_path.exist?
|
95
|
+
end
|
96
|
+
|
97
|
+
def descend( *args, &block )
|
98
|
+
if @current_path.directory?
|
99
|
+
close_file
|
100
|
+
@paths << @current_path
|
101
|
+
@current_path = @paths.last.join( *args )
|
102
|
+
make_path
|
103
|
+
yield
|
104
|
+
@current_path = @paths.pop
|
105
|
+
close_file
|
106
|
+
else
|
107
|
+
raise "Cannot descend."
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def open_file( name )
|
112
|
+
close_file
|
113
|
+
@current_file = File.open( @current_path.join( name ), "w" )
|
114
|
+
end
|
115
|
+
|
116
|
+
def close_file
|
117
|
+
if @current_file
|
118
|
+
@current_file.flush
|
119
|
+
@current_file.close
|
120
|
+
end
|
121
|
+
|
122
|
+
@current_file = nil
|
123
|
+
end
|
124
|
+
|
125
|
+
def download_to_target( url, file )
|
126
|
+
Downloader.new.download( url, file )
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
# sample code
|
134
|
+
#
|
135
|
+
# DirBuilder.create( '~/project' ) do |b| # starts by creating directory. If parent
|
136
|
+
# # directories don't exist, they will soon.
|
137
|
+
# # if you use DirBuilder.tmp('~/project'), a tempdir
|
138
|
+
# # is created, and its contents relocated to ~/project when the
|
139
|
+
# # block terminates.
|
140
|
+
# b.dir("images") do # creates subdirectory "images"
|
141
|
+
# for img in src_dir.entries.select{|img| img.extension == ".png"}
|
142
|
+
# b.copy( src_dir.join( img.filename ) ) # copies a bunch of files from another directory
|
143
|
+
# end # rises back to the initial '~/project directory
|
144
|
+
#
|
145
|
+
# b.copy( src_dir.join( "rorshach.xml" ) )
|
146
|
+
# b.download( "dest.bash", "http://get.rvm.io" ) # downloads file directly beneath '~/project'
|
147
|
+
# # maybe someday, though
|
148
|
+
#
|
149
|
+
# b.dir("text", "scenes") do # creates ~/project/text/scenes subdir
|
150
|
+
# b.file( "adventure_time.txt" ) do |f|
|
151
|
+
# f << "Fill this in later"
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# # calling .file without feeding it a block leaves it open for writing,
|
155
|
+
# # until either the enclosing block terminates or .file is called
|
156
|
+
# # again with a string argument.
|
157
|
+
# b.file( "another_brick.txt" )
|
158
|
+
# b.file << "Hey, you!"
|
159
|
+
# b.file << "Yes, you!"
|
160
|
+
# b.file.push "Stand still, laddie!"
|
161
|
+
#
|
162
|
+
# b.template(templates_dir.join("blue_template.txt")) do |t|
|
163
|
+
# t.var(:fname, "John")
|
164
|
+
# t.var(:lname, "Macey")
|
165
|
+
# t.var(:state, "Ohio")
|
166
|
+
# t.vars(graduated: "2003")
|
167
|
+
# t.vars(quot: "That wasn't my duck.", photo: "john.png", css: "font-family: arial")
|
168
|
+
# end
|
169
|
+
#
|
170
|
+
# b.copy( [src_dir.join("abba.txt"), "baab.txt"] ) # contents of abba.txt copied into baab.txt
|
171
|
+
#
|
172
|
+
#
|
173
|
+
# b.file( ".lockfile" ) # creates an empty file
|
174
|
+
# end
|
175
|
+
#
|
176
|
+
# b.
|
177
|
+
# end
|
178
|
+
#
|
179
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'open-uri' # needed by Utils::Downloader
|
2
|
+
require 'net/http'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
|
6
|
+
module FunWith
|
7
|
+
module Files
|
8
|
+
class Downloader
|
9
|
+
# stolen from:
|
10
|
+
# http://stackoverflow.com/questions/2263540/how-do-i-download-a-binary-file-over-http-using-ruby
|
11
|
+
def download( url, io )
|
12
|
+
@uri = URI.parse( url )
|
13
|
+
@io = io
|
14
|
+
|
15
|
+
open( url ) do |f|
|
16
|
+
@io << f.read
|
17
|
+
end
|
18
|
+
|
19
|
+
# @io << Net::HTTP.get( @uri )
|
20
|
+
|
21
|
+
# Net::HTTP.start( @uri.host, @uri.port ) do |http|
|
22
|
+
# http.request_get( @uri.path ) do |request|
|
23
|
+
# request.read_body do |seg|
|
24
|
+
# puts "============================== #{seg} ============================="
|
25
|
+
# io << seg
|
26
|
+
# #hack -- adjust to suit:
|
27
|
+
# sleep 0.005
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
rescue Exception => e
|
32
|
+
handle_network_errors( e )
|
33
|
+
end
|
34
|
+
|
35
|
+
def handle_network_errors( e )
|
36
|
+
raise e
|
37
|
+
rescue URI::InvalidURIError => e
|
38
|
+
puts "Tried to get #{@uri.path} but failed with URI::InvalidURIError."
|
39
|
+
rescue OpenURI::HTTPError => e
|
40
|
+
STDERR.write( "Couldn't fetch podcast info from #{@uri.path}\n" )
|
41
|
+
STDERR.write( "#{e}\n\n" )
|
42
|
+
rescue SocketError => e
|
43
|
+
STDERR.write( "Problem connecting to server (Socket error) when downloading #{@uri.path}." )
|
44
|
+
STDERR.write( "#{e}\n\n" )
|
45
|
+
rescue URI::InvalidURIError => e
|
46
|
+
STDERR.write( "URI::InvalidURIError for #{@uri.path}." )
|
47
|
+
STDERR.write( "#{e}\n\n" )
|
48
|
+
# this may be too broad a filter
|
49
|
+
# TODO: retry?
|
50
|
+
rescue SystemCallError => e
|
51
|
+
STDERR.write( "Problem connecting to server (System call error) when downloading #{@uri.path}" )
|
52
|
+
STDERR.write( "#{e}\n\n" )
|
53
|
+
rescue OpenSSL::SSL::SSLError => e
|
54
|
+
STDERR.write( "OpenSSL::SSL::SSLError while downloading #{@uri.path}" )
|
55
|
+
STDERR.write( "#{e}\n\n" )
|
56
|
+
rescue Timeout::Error
|
57
|
+
STDERR.write( "Timeout error connecting to #{@uri.path}" )
|
58
|
+
STDERR.write( "#{e}\n\n" )
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Files
|
3
|
+
# FileOrderer holds a set of strings/regexes, then reorders a set of files (FunWith::Files::FilePaths, actually)
|
4
|
+
# by matching the filenames against one regex after another. Allows you to say,
|
5
|
+
# "I want the title page, the foreward, then all the chapters, then all the appendixes, then the afterword."
|
6
|
+
# Ex: FileOrderer( ["title_page", "forward", "chapter-.*", "afterword", "appendix.*" ).reorder( pages )
|
7
|
+
# Only compares the basename minus extension. Files should come from the same directory. cover.extension always comes first.
|
8
|
+
class FileOrderer
|
9
|
+
def initialize( matchers )
|
10
|
+
@matchers = matchers.map do |m|
|
11
|
+
case m
|
12
|
+
when Regexp
|
13
|
+
m
|
14
|
+
when String
|
15
|
+
/^#{m}$/
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
@matchers.unshift( /^cover$/ )
|
20
|
+
@matchers.push( /^.*$/ )
|
21
|
+
end
|
22
|
+
|
23
|
+
def reorder( files )
|
24
|
+
files = files.map(&:fwf_filepath)
|
25
|
+
|
26
|
+
ordered_files = @matchers.inject( [] ) do |collector, matcher|
|
27
|
+
matched_files = files.select do |f|
|
28
|
+
name = f.basename_no_ext.to_s
|
29
|
+
matcher.match( name )
|
30
|
+
end
|
31
|
+
|
32
|
+
matched_files.sort_by! do |filename|
|
33
|
+
filename.basename_no_ext.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
collector += matched_files.sort
|
37
|
+
files -= matched_files
|
38
|
+
|
39
|
+
collector
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/files/file_path.rb
CHANGED
@@ -14,6 +14,11 @@ module FunWith
|
|
14
14
|
self.cwd( *args )
|
15
15
|
end
|
16
16
|
|
17
|
+
# If block given, temporary directory is deleted at the end of the block, and the
|
18
|
+
# value given by the block is returned.
|
19
|
+
#
|
20
|
+
# If no block given, the path to the temp directory is returned as a FilePath.
|
21
|
+
# Don't forget to delete it when you're done.
|
17
22
|
def self.tmpdir( &block )
|
18
23
|
if block_given?
|
19
24
|
Dir.mktmpdir do |d|
|
@@ -28,6 +33,10 @@ module FunWith
|
|
28
33
|
Dir.home.fwf_filepath.join( *args )
|
29
34
|
end
|
30
35
|
|
36
|
+
def self.template( src, dest, vars = {} )
|
37
|
+
raise "require 'fun_with_templates' to use this method"
|
38
|
+
end
|
39
|
+
|
31
40
|
def join( *args, &block )
|
32
41
|
if block_given?
|
33
42
|
yield self.class.new( super(*args) )
|
@@ -38,6 +47,8 @@ module FunWith
|
|
38
47
|
|
39
48
|
alias :exists? :exist?
|
40
49
|
|
50
|
+
# If called on a file instead of a directory,
|
51
|
+
# has the same effect as path.dirname
|
41
52
|
def up
|
42
53
|
self.class.new( self.join("..") ).expand
|
43
54
|
end
|
@@ -169,6 +180,7 @@ module FunWith
|
|
169
180
|
end
|
170
181
|
end
|
171
182
|
|
183
|
+
# Returns a [list] of the lines in the file matching the given file
|
172
184
|
def grep( regex )
|
173
185
|
return [] unless self.file?
|
174
186
|
matching = []
|
@@ -207,23 +219,21 @@ module FunWith
|
|
207
219
|
|
208
220
|
# base, ext = @path.basename_and_ext
|
209
221
|
def basename_and_ext
|
210
|
-
[basename_no_ext, ext]
|
222
|
+
[self.basename_no_ext, self.ext]
|
211
223
|
end
|
212
224
|
|
213
|
-
|
214
|
-
|
215
|
-
dir = super( Pathname.new( dir ) )
|
216
|
-
self.class.new( dir )
|
225
|
+
def dirname_and_basename
|
226
|
+
[self.dirname, self.basename]
|
217
227
|
end
|
218
228
|
|
219
|
-
|
220
|
-
|
221
|
-
self.to_s.gsub(*args).fwf_filepath
|
229
|
+
def dirname_and_basename_and_ext
|
230
|
+
[self.dirname, self.basename_no_ext, self.ext]
|
222
231
|
end
|
223
232
|
|
224
|
-
|
225
|
-
|
226
|
-
|
233
|
+
# Basically Pathname.relative_path_from, but you can pass in strings
|
234
|
+
def relative_path_from( dir )
|
235
|
+
dir = super( Pathname.new( dir ) )
|
236
|
+
self.class.new( dir )
|
227
237
|
end
|
228
238
|
|
229
239
|
def fwf_filepath
|
@@ -339,10 +349,7 @@ module FunWith
|
|
339
349
|
FileUtils.rmtree( self )
|
340
350
|
end
|
341
351
|
end
|
342
|
-
|
343
|
-
def =~( rval )
|
344
|
-
self.to_s =~ rval
|
345
|
-
end
|
352
|
+
|
346
353
|
|
347
354
|
def load
|
348
355
|
if self.directory?
|
@@ -360,6 +367,32 @@ module FunWith
|
|
360
367
|
require self.expand.gsub( /\.rb$/, '' )
|
361
368
|
end
|
362
369
|
end
|
370
|
+
|
371
|
+
def root?
|
372
|
+
self == self.up
|
373
|
+
end
|
374
|
+
|
375
|
+
def descend( &block )
|
376
|
+
path = self.clone
|
377
|
+
|
378
|
+
if path.root?
|
379
|
+
yield path
|
380
|
+
else
|
381
|
+
self.up.descend( &block )
|
382
|
+
yield self
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
def ascend( &block )
|
387
|
+
path = self.clone
|
388
|
+
|
389
|
+
if path.root?
|
390
|
+
yield path
|
391
|
+
else
|
392
|
+
yield self
|
393
|
+
self.up.ascend( &block )
|
394
|
+
end
|
395
|
+
end
|
363
396
|
end
|
364
397
|
end
|
365
398
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Allow FilePaths to participate in some of the String-based mischief.
|
2
|
+
|
3
|
+
module FunWith
|
4
|
+
module Files
|
5
|
+
module StringBehavior
|
6
|
+
def =~( rval )
|
7
|
+
@path =~ rval
|
8
|
+
end
|
9
|
+
|
10
|
+
def match( *args )
|
11
|
+
@path.match( *args )
|
12
|
+
end
|
13
|
+
|
14
|
+
# gsub acts on the filepath, not the file contents
|
15
|
+
def gsub( *args )
|
16
|
+
@path.gsub(*args).fwf_filepath
|
17
|
+
end
|
18
|
+
|
19
|
+
def gsub!( *args )
|
20
|
+
@path = @path.gsub(*args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/fun_with_files.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
require 'pathname' #stdlib
|
2
2
|
require 'tmpdir'
|
3
|
-
require
|
3
|
+
require 'debugger'
|
4
4
|
|
5
|
-
for file in %w(
|
5
|
+
for file in %w(directory_builder
|
6
|
+
downloader
|
7
|
+
file_orderer
|
8
|
+
file_path
|
9
|
+
root_path
|
10
|
+
remote_path
|
11
|
+
string_extensions
|
12
|
+
string_behavior
|
13
|
+
pathname_extensions
|
14
|
+
xdg_extensions)
|
15
|
+
|
6
16
|
require_relative File.join("files", file)
|
7
17
|
end
|
8
18
|
|
9
19
|
FunWith::Files::RootPath.rootify( FunWith::Files, __FILE__.fwf_filepath.dirname.up )
|
10
20
|
FunWith::Files::VERSION = FunWith::Files.root("VERSION").read
|
21
|
+
|
22
|
+
FunWith::Files::FilePath.send( :include, FunWith::Files::StringBehavior )
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestDescent < FunWith::Files::TestCase
|
4
|
+
should "descend and ascend" do
|
5
|
+
root = FunWith::Files.root
|
6
|
+
|
7
|
+
ascent = []
|
8
|
+
descent = []
|
9
|
+
|
10
|
+
FunWith::Files.root.ascend do |path|
|
11
|
+
ascent << path
|
12
|
+
end
|
13
|
+
|
14
|
+
FunWith::Files.root.descend do |path|
|
15
|
+
descent << path
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_equal ascent, descent.reverse
|
19
|
+
assert_equal ascent[1], ascent[0].up
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestDirectoryBuilder < FunWith::Files::TestCase
|
4
|
+
context "tearing my hair out because shoulda seems borked" do
|
5
|
+
should "stop blaming shoulda for my problems" do
|
6
|
+
assert true
|
7
|
+
end
|
8
|
+
|
9
|
+
should "realize that assert statements need to be inside should blocks" do
|
10
|
+
assert "Okay, okay. I get it. Now lay off me."
|
11
|
+
end
|
12
|
+
|
13
|
+
should "figure out why the hell [].is_a?(Array) returns false" do
|
14
|
+
assert_kind_of Array, []
|
15
|
+
assert [].is_a?(Array)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "In a temporary directory" do
|
20
|
+
should "create a temporary directory" do
|
21
|
+
DirectoryBuilder.tmpdir do |b|
|
22
|
+
assert_equal DirectoryBuilder, b.class #
|
23
|
+
assert b.current_path.exist?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
should "write data to a new file" do
|
28
|
+
DirectoryBuilder.tmpdir do |b|
|
29
|
+
assert_equal DirectoryBuilder, b.class
|
30
|
+
assert b.current_path
|
31
|
+
assert b.current_path.exist?
|
32
|
+
b.file("widdershins.txt") do |f|
|
33
|
+
f << "Hello World"
|
34
|
+
f.flush
|
35
|
+
|
36
|
+
assert b.current_file.exist?
|
37
|
+
assert_equal 11, b.current_file.size
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should "copy files from elsewhere into the directory" do
|
43
|
+
DirectoryBuilder.tmpdir do |b|
|
44
|
+
assert_equal DirectoryBuilder, b.class
|
45
|
+
src = FunWith::Files.root.join("Gemfile")
|
46
|
+
assert src.exist?
|
47
|
+
|
48
|
+
b.copy( FunWith::Files.root.join("Gemfile") )
|
49
|
+
|
50
|
+
gemfile = b.current_path.join("Gemfile")
|
51
|
+
assert gemfile.exist?
|
52
|
+
assert !gemfile.zero?
|
53
|
+
assert_equal 1, gemfile.grep( /jeweler/ ).length
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
should "copy files from elsewhere, renaming the file in the destination" do
|
58
|
+
DirectoryBuilder.tmpdir do |b|
|
59
|
+
assert_equal DirectoryBuilder, b.class
|
60
|
+
assert !b.current_path.join("helpers.rb").exist?
|
61
|
+
b.copy( FunWith::Files.root("lib", "fun_with_files.rb"), "fwf.rb" )
|
62
|
+
assert b.current_path.join("fwf.rb").exist?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
should "download random crap from all over the Internet" do
|
67
|
+
DirectoryBuilder.tmpdir do |b|
|
68
|
+
gist_url = "http://bannedsorcery.com/downloads/testfile.txt"
|
69
|
+
gist_text = "This is a file\n==============\n\n**silent**: But _bold_! [Link](http://slashdot.org)\n"
|
70
|
+
b.download( gist_url, "gist.txt" )
|
71
|
+
|
72
|
+
b.file( "gist.txt.2" ) do
|
73
|
+
b.download( gist_url )
|
74
|
+
end
|
75
|
+
|
76
|
+
assert b.current_file.nil?
|
77
|
+
assert b.current_path.join("gist.txt").exist?
|
78
|
+
assert b.current_path.join("gist.txt.2").exist?
|
79
|
+
assert_equal gist_text, b.current_path.join("gist.txt").read
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
should "exercise all manner of features to create a complex directory" do
|
84
|
+
DirectoryBuilder.tmpdir do |b|
|
85
|
+
assert_equal DirectoryBuilder, b.class
|
86
|
+
root = FunWith::Files.root
|
87
|
+
gemfile = root.join("Gemfile")
|
88
|
+
b.copy( gemfile )
|
89
|
+
assert gemfile.exist?
|
90
|
+
assert_equal gemfile.size, b.current_path.join("Gemfile").size
|
91
|
+
|
92
|
+
b.dir( "earth" ) do
|
93
|
+
b.dir( "air") do
|
94
|
+
b.dir( "fire" ) do
|
95
|
+
b.dir( "water" ) do
|
96
|
+
b.file( "hello.txt" )
|
97
|
+
b.file << "H"
|
98
|
+
b.file << "e"
|
99
|
+
b.file << "l"
|
100
|
+
b.file << "l"
|
101
|
+
b.file << "o"
|
102
|
+
end
|
103
|
+
|
104
|
+
assert b.current_file.nil?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
assert "Hello", b.current_path.join("earth", "air", "fire", "water", "hello.txt").read
|
110
|
+
|
111
|
+
b.dir( "fire", "water", "earth", "air" ) do
|
112
|
+
assert b.current_path.exist?
|
113
|
+
b.copy( FunWith::Files.root.join("Gemfile"), "Gemfile.example" )
|
114
|
+
b.copy( FunWith::Files.root.join("Gemfile.lock"), "Gemfile.lock.example" )
|
115
|
+
b.copy( FunWith::Files.root.join("Rakefile"), "Rakefile" )
|
116
|
+
|
117
|
+
for file in %W(Gemfile.example Gemfile.lock.example Rakefile)
|
118
|
+
assert b.current_path.join(file).exist?, "#{file} should exist"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
directory = ["air", "earth", "water", "fire"]
|
123
|
+
b.dir( *directory ) do
|
124
|
+
b.file( "slipstream.txt", "file contents" )
|
125
|
+
end
|
126
|
+
|
127
|
+
assert b.current_path.join(*directory).exist?
|
128
|
+
slip = b.current_path.join(*directory).join("slipstream.txt")
|
129
|
+
assert slip.exist?
|
130
|
+
assert_equal false, slip.empty?
|
131
|
+
assert_equal "file contents", b.current_path.join(*directory).join( "slipstream.txt" ).read
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
data/test/test_file_path.rb
CHANGED
data/test/test_globbing.rb
CHANGED
data/test/test_loading.rb
CHANGED
data/test/test_root_path.rb
CHANGED
data/test/test_touching.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fun_with_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: xdg
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: debugger
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,11 +121,16 @@ extra_rdoc_files:
|
|
105
121
|
- LICENSE.txt
|
106
122
|
- README.rdoc
|
107
123
|
files:
|
124
|
+
- ./lib/files/directory_builder.rb
|
125
|
+
- ./lib/files/downloader.rb
|
126
|
+
- ./lib/files/file_orderer.rb
|
108
127
|
- ./lib/files/file_path.rb
|
109
128
|
- ./lib/files/pathname_extensions.rb
|
110
129
|
- ./lib/files/remote_path.rb
|
111
130
|
- ./lib/files/root_path.rb
|
131
|
+
- ./lib/files/string_behavior.rb
|
112
132
|
- ./lib/files/string_extensions.rb
|
133
|
+
- ./lib/files/xdg_extensions.rb
|
113
134
|
- ./lib/fun_with_files.rb
|
114
135
|
- ./test/data/empty.txt
|
115
136
|
- ./test/data/grep1.txt
|
@@ -119,6 +140,8 @@ files:
|
|
119
140
|
- ./test/loadable_dir/dir2/file2.rb
|
120
141
|
- ./test/loadable_dir/dir3/file3.rb
|
121
142
|
- ./test/loadable_dir/dir4/file4.rb
|
143
|
+
- ./test/test_descent.rb
|
144
|
+
- ./test/test_directory_builder.rb
|
122
145
|
- ./test/test_file_path.rb
|
123
146
|
- ./test/test_globbing.rb
|
124
147
|
- ./test/test_loading.rb
|
@@ -144,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
167
|
version: '0'
|
145
168
|
segments:
|
146
169
|
- 0
|
147
|
-
hash: -
|
170
|
+
hash: -363617118462161826
|
148
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
172
|
none: false
|
150
173
|
requirements:
|