fun_with_files 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.rdoc +1 -1
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/lib/fun_with/files/core_extensions/{false.rb → false_class.rb} +0 -0
- data/lib/fun_with/files/core_extensions/file.rb +15 -3
- data/lib/fun_with/files/core_extensions/{nil.rb → nil_class.rb} +0 -0
- data/lib/fun_with/files/core_extensions/set.rb +12 -0
- data/lib/fun_with/files/core_extensions/true_class.rb +11 -0
- data/lib/fun_with/files/digest_methods.rb +20 -1
- data/lib/fun_with/files/directory_builder.rb +5 -4
- data/lib/fun_with/files/downloader.rb +31 -2
- data/lib/fun_with/files/file_orderer.rb +2 -0
- data/lib/fun_with/files/file_path.rb +94 -5
- data/lib/fun_with_files.rb +49 -5
- data/test/test_core_extensions.rb +1 -0
- data/test/test_descent.rb +2 -2
- data/test/test_directory_builder.rb +2 -2
- data/test/test_file_manipulation.rb +2 -2
- data/test/test_file_path.rb +66 -18
- data/test/test_fun_with_files.rb +1 -1
- metadata +13 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d1ccc274aea1937c63f81c2fe7897349aadbdc9
|
4
|
+
data.tar.gz: 5ae174de323cfa4aba42d459b5848416c173bcfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8125f7794e66f690c5180e88f6d827463d251878417e1689e2360bac84ad9d9909530a2c299409468558320817763a2d66ac4bf45308e6cacdca26363a63eda4
|
7
|
+
data.tar.gz: 13c43cb5c978693715ffa1a21c72c07c464eaab0deb4260826b49d120748967ed7fd20c65234888347a2a96ab59529a6517a10c304dc99d9cf0bae33046661c1
|
data/Gemfile
CHANGED
@@ -10,9 +10,9 @@ group :development do
|
|
10
10
|
# gem "shoulda", "~> 3", ">= 3.5"
|
11
11
|
# gem "rdoc", "~> 3.12"
|
12
12
|
# gem "bundler", "~> 1.5"
|
13
|
-
# gem "
|
13
|
+
# gem "juwelier", "~> 2.0"
|
14
14
|
# gem "debugger", "~> 1.6"
|
15
|
-
gem "fun_with_testing", "~> 0.0"
|
15
|
+
gem "fun_with_testing", "~> 0.0", ">= 0.0.5"
|
16
16
|
end
|
17
17
|
|
18
18
|
gem "xdg", "~> 2"
|
data/README.rdoc
CHANGED
@@ -108,7 +108,7 @@ DirectoryBuilder is a class for defining and populating a file hierarchy with re
|
|
108
108
|
|
109
109
|
== Contributing to fun_with_files
|
110
110
|
|
111
|
-
Boilerplate from
|
111
|
+
Boilerplate from Juwelier, but seems to make sense.
|
112
112
|
|
113
113
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
114
114
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
data/Rakefile
CHANGED
@@ -14,8 +14,8 @@ end
|
|
14
14
|
|
15
15
|
require 'rake'
|
16
16
|
|
17
|
-
# require '
|
18
|
-
|
17
|
+
# require 'juwelier'
|
18
|
+
Juwelier::Tasks.new do |gem|
|
19
19
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
20
20
|
gem.name = "fun_with_files"
|
21
21
|
gem.homepage = "http://github.com/darthschmoo/fun_with_files"
|
@@ -50,7 +50,7 @@ DESC
|
|
50
50
|
]
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
Juwelier::RubygemsDotOrgTasks.new
|
54
54
|
|
55
55
|
require 'rake/testtask'
|
56
56
|
Rake::TestTask.new(:test) do |test|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.15
|
File without changes
|
@@ -1,5 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module FunWith
|
2
|
+
module Files
|
3
|
+
module CoreExtensions
|
4
|
+
module File
|
5
|
+
def fwf_filepath( *args )
|
6
|
+
FunWith::Files::FilePath.new( self.path, *args )
|
7
|
+
end
|
8
|
+
|
9
|
+
# I'm not sure this is the most intuitive meaning, but it seems better than
|
10
|
+
# delegating to Object.
|
11
|
+
def fwf_blank?
|
12
|
+
! self.fwf_filepath.exist?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
4
16
|
end
|
5
17
|
end
|
File without changes
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module FunWith
|
2
2
|
module Files
|
3
|
+
DIGEST_METHODS = [:md5, :sha1, :sha2, :sha224, :sha256, :sha384, :sha512]
|
4
|
+
|
3
5
|
module DigestMethods
|
4
6
|
def md5
|
5
7
|
digest( Digest::MD5 )
|
@@ -28,10 +30,27 @@ module FunWith
|
|
28
30
|
def sha512
|
29
31
|
digest( Digest::SHA512 )
|
30
32
|
end
|
31
|
-
|
33
|
+
|
32
34
|
def digest( digest_class = Digest::MD5 )
|
33
35
|
self.file? ? digest_class.hexdigest( self.read ) : ""
|
34
36
|
end
|
37
|
+
|
38
|
+
# Takes any of the above-named digest functions, determines
|
39
|
+
# whether the file matches a given digest string.
|
40
|
+
#
|
41
|
+
# Multiple digests can be given simultaneously. All must pass.
|
42
|
+
#
|
43
|
+
# TODO: how to get around the :md6 problem? That is, where the
|
44
|
+
# user is sending the wrong key, and hence not getting false back
|
45
|
+
def valid_digest?( opts )
|
46
|
+
for method, digest in opts
|
47
|
+
if DIGEST_METHODS.include?( method )
|
48
|
+
return false unless self.send( method ) == digest
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
return true
|
53
|
+
end
|
35
54
|
end
|
36
55
|
end
|
37
56
|
end
|
@@ -9,6 +9,7 @@ module FunWith
|
|
9
9
|
def initialize( path )
|
10
10
|
@paths = []
|
11
11
|
@current_path = path.fwf_filepath
|
12
|
+
@current_file = nil
|
12
13
|
make_path
|
13
14
|
end
|
14
15
|
|
@@ -79,7 +80,7 @@ module FunWith
|
|
79
80
|
# end
|
80
81
|
|
81
82
|
# if file not given, the result is appended to the current file.
|
82
|
-
def download( url, file = nil )
|
83
|
+
def download( url, file = nil, opts = {} )
|
83
84
|
if file
|
84
85
|
if file.fwf_filepath.relative?
|
85
86
|
file = FunWith::Files::FilePath.new( @current_path, file )
|
@@ -89,7 +90,7 @@ module FunWith
|
|
89
90
|
download_to_target( url, f )
|
90
91
|
end
|
91
92
|
elsif @current_file
|
92
|
-
download_to_target( url, @current_file )
|
93
|
+
download_to_target( url, @current_file, opts )
|
93
94
|
else
|
94
95
|
puts "No current file to append #{url} to."
|
95
96
|
end
|
@@ -132,8 +133,8 @@ module FunWith
|
|
132
133
|
@current_file = nil
|
133
134
|
end
|
134
135
|
|
135
|
-
def download_to_target( url, file )
|
136
|
-
Downloader.new.download( url, file )
|
136
|
+
def download_to_target( url, file, signatures = {} )
|
137
|
+
Downloader.new.download( url, file, signatures )
|
137
138
|
end
|
138
139
|
end
|
139
140
|
end
|
@@ -1,21 +1,46 @@
|
|
1
1
|
require 'open-uri' # needed by Utils::Downloader
|
2
2
|
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'openssl'
|
3
5
|
require 'timeout'
|
4
6
|
|
5
7
|
|
6
8
|
module FunWith
|
7
9
|
module Files
|
8
10
|
class Downloader
|
11
|
+
def self.download( *args )
|
12
|
+
self.new.download( *args )
|
13
|
+
end
|
14
|
+
|
9
15
|
# stolen from:
|
10
16
|
# http://stackoverflow.com/questions/2263540/how-do-i-download-a-binary-file-over-http-using-ruby
|
11
|
-
|
17
|
+
|
18
|
+
# options:
|
19
|
+
# :md5 => <digest> : Running md5 on the downloaded file should result in an error
|
20
|
+
# :sha256 => <digest> :
|
21
|
+
def download( url, io, opts = {} )
|
12
22
|
@uri = URI.parse( url )
|
13
23
|
@io = io
|
14
24
|
|
15
25
|
open( url ) do |f|
|
16
26
|
@io << f.read
|
17
27
|
end
|
18
|
-
|
28
|
+
|
29
|
+
io_path = @io.fwf_filepath
|
30
|
+
|
31
|
+
if io_path.file?
|
32
|
+
if io_path.valid_digest?( opts )
|
33
|
+
true
|
34
|
+
else
|
35
|
+
warn( "File may not have downloaded correctly, or is validating against a bad hash #{io_path} #{opts.inspect}")
|
36
|
+
false
|
37
|
+
|
38
|
+
end
|
39
|
+
else
|
40
|
+
warn( "File did not download correctly, or was deleted: #{io_path}")
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
19
44
|
# @io << Net::HTTP.get( @uri )
|
20
45
|
|
21
46
|
# Net::HTTP.start( @uri.host, @uri.port ) do |http|
|
@@ -28,6 +53,10 @@ module FunWith
|
|
28
53
|
# end
|
29
54
|
# end
|
30
55
|
# end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
31
60
|
rescue Exception => e
|
32
61
|
handle_network_errors( e )
|
33
62
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module FunWith
|
2
2
|
module Files
|
3
3
|
class FilePath < Pathname
|
4
|
-
|
5
4
|
SUCC_DIGIT_COUNT = 6
|
6
5
|
DEFAULT_TIMESTAMP_FORMAT = "%Y%m%d%H%M%S%L"
|
7
|
-
|
6
|
+
|
8
7
|
def initialize( *args )
|
9
8
|
super( File.join( *args ) )
|
10
9
|
end
|
@@ -25,9 +24,22 @@ module FunWith
|
|
25
24
|
Dir.mktmpdir.fwf_filepath
|
26
25
|
end
|
27
26
|
end
|
27
|
+
|
28
|
+
# The file is created within a temporary directory
|
29
|
+
def self.tmpfile( ext = :tmp, &block )
|
30
|
+
filename = rand( 2 ** 64 ).to_s(16).fwf_filepath.ext( ext )
|
31
|
+
|
32
|
+
if block_given?
|
33
|
+
self.tmpdir do |tmp|
|
34
|
+
yield tmp.join( filename ).touch
|
35
|
+
end
|
36
|
+
else
|
37
|
+
self.tmpdir.join( filename ).touch
|
38
|
+
end
|
39
|
+
end
|
28
40
|
|
29
41
|
def join( *args, &block )
|
30
|
-
joined_path = self.class.new( super(*args) )
|
42
|
+
joined_path = self.class.new( super( *(args.map(&:to_s) ) ) )
|
31
43
|
yield joined_path if block_given?
|
32
44
|
joined_path
|
33
45
|
end
|
@@ -273,6 +285,8 @@ module FunWith
|
|
273
285
|
end
|
274
286
|
end
|
275
287
|
end
|
288
|
+
|
289
|
+
alias :<< :append
|
276
290
|
|
277
291
|
# Returns a [list] of the lines in the file matching the given file. Contrast with
|
278
292
|
|
@@ -302,12 +316,84 @@ module FunWith
|
|
302
316
|
end
|
303
317
|
|
304
318
|
# Does not return a filepath
|
319
|
+
#
|
320
|
+
# TODO: Why not?
|
305
321
|
def basename_no_ext
|
306
322
|
self.basename.to_s.split(".")[0..-2].join(".")
|
307
323
|
end
|
308
324
|
|
309
|
-
|
310
|
-
|
325
|
+
# Returns the path, stripped of the final extension (.ARG).
|
326
|
+
# The result cannot destroy a dotfile or leave an empty
|
327
|
+
# path
|
328
|
+
# "~/.bashrc".without_ext( .bashrc ) => "~/.bashrc",
|
329
|
+
# if an argument is given, the final ext must match
|
330
|
+
# the given argument, or a copy of the unaltered path
|
331
|
+
# is returned.
|
332
|
+
#
|
333
|
+
# Also:
|
334
|
+
# Don't add a leading ./ when the original didn't have one
|
335
|
+
# Case InSeNSItive, because I can't think of a use case for "only"
|
336
|
+
# strip the extension if the capitalization matches
|
337
|
+
# Chews up any number of leading '.'s
|
338
|
+
# For the moment,
|
339
|
+
def without_ext( ext_val = nil )
|
340
|
+
ext_chopper_regex = if ext_val.fwf_blank?
|
341
|
+
/\.+\w+$/i # any ending "word characters"
|
342
|
+
else
|
343
|
+
# It's okay for the caller to make the leading period explicit
|
344
|
+
ext_val = ext_val.to_s.gsub( /^\./, '' )
|
345
|
+
/\.+#{ext_val}+$/i
|
346
|
+
end
|
347
|
+
|
348
|
+
chopped_str = @path.gsub( ext_chopper_regex, "" )
|
349
|
+
|
350
|
+
do_we_chop = if chopped_str == @path # no change, then sure, why not?
|
351
|
+
true
|
352
|
+
elsif chopped_str.fwf_blank? || chopped_str[-1] == self.separator() || chopped_str[-1] == "."
|
353
|
+
false
|
354
|
+
else
|
355
|
+
true
|
356
|
+
end
|
357
|
+
|
358
|
+
self.class.new( do_we_chop ? chopped_str : @path )
|
359
|
+
|
360
|
+
# # If the results fail to live up to some pre-defined
|
361
|
+
#
|
362
|
+
#
|
363
|
+
#
|
364
|
+
# # do we or don't we?
|
365
|
+
# chop_extension = true
|
366
|
+
#
|
367
|
+
# # Don't if there's an extension mismatch
|
368
|
+
# # Don't if the remainder is a /. (original was a dot_file)
|
369
|
+
#
|
370
|
+
#
|
371
|
+
#
|
372
|
+
#
|
373
|
+
#
|
374
|
+
#
|
375
|
+
# _dirname, _basename, _ext = self.dirname_and_basename_and_ext
|
376
|
+
# debugger if _basename =~ "hello"
|
377
|
+
# ext_val = ext_val.to_s
|
378
|
+
#
|
379
|
+
# # 1) Only perform if the extension match the one given (or was a blank ext given?)
|
380
|
+
#
|
381
|
+
#
|
382
|
+
#
|
383
|
+
# new_path = @path.clone
|
384
|
+
#
|
385
|
+
# current_ext = self.ext
|
386
|
+
#
|
387
|
+
# e = e.to_s
|
388
|
+
#
|
389
|
+
# if e.fwf_present?
|
390
|
+
# new_path.gsub!( /\.#{e}$/, "" )
|
391
|
+
# result = self.gsub(/#{ not_beginning_of_line_or_separator}\.#{self.ext}$/, '')
|
392
|
+
# else
|
393
|
+
# self.clone
|
394
|
+
# end
|
395
|
+
#
|
396
|
+
# self.class.new( new_path )
|
311
397
|
end
|
312
398
|
|
313
399
|
# Two separate modes. With no arguments given, returns the current extension as a string (not a filepath)
|
@@ -584,6 +670,9 @@ module FunWith
|
|
584
670
|
# end
|
585
671
|
# # otherwise we're installing a separator
|
586
672
|
# end
|
673
|
+
def separator
|
674
|
+
File::SEPARATOR
|
675
|
+
end
|
587
676
|
|
588
677
|
protected
|
589
678
|
# TODO: Need a separate API for user to call
|
data/lib/fun_with_files.rb
CHANGED
@@ -4,15 +4,59 @@ require 'pathname' # stdlib
|
|
4
4
|
require 'tmpdir' # Dir.tmpdir
|
5
5
|
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# Do the bare minimum to get FilePath.requir working
|
8
|
+
# file_path = File.join( "fun_with", "files", "file_path" )
|
9
|
+
# string_behavior = File.join( "fun_with", "files", "string_behavior" )
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# require_relative file_path
|
13
|
+
# require_relative string_behavior
|
14
|
+
#
|
15
|
+
# FunWith::Files::FilePath.send( :include, FunWith::Files::StringBehavior )
|
16
|
+
# FunWith::Files::FilePath.new( "fun_with" ).requir
|
17
|
+
#
|
18
|
+
# debugger
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
core_extension_folder = File.join( "lib", "fun_with", "files", "core_extensions" )
|
10
23
|
|
11
|
-
for
|
12
|
-
|
24
|
+
for fil in Dir.glob( File.join( core_extension_folder, "*.rb" ) )
|
25
|
+
# Dir.glob targets the root directory, while require_relative is relative to lib/,
|
26
|
+
# so the [4..-4] removes the leading lib/ and the trailing extension to make it
|
27
|
+
# require_relative-friendly.
|
28
|
+
require_path = fil[4..-4] #
|
29
|
+
basename = File.basename( fil )[0..-4]
|
30
|
+
# debugger if basename =~ /class/
|
31
|
+
|
32
|
+
target_class_str = basename.split( "_" ).map(&:capitalize).join("")
|
33
|
+
target_class = Kernel.const_get( target_class_str )
|
34
|
+
mixin_class_str = "FunWith::Files::CoreExtensions::#{target_class_str}"
|
35
|
+
|
36
|
+
# puts "Basename: #{basename}"
|
37
|
+
# puts "Mixin: " + mixin_class_str.inspect
|
38
|
+
# puts "Target: #{target_class}"
|
39
|
+
# puts "requiring: #{require_path}"
|
40
|
+
require_relative require_path
|
41
|
+
mixin_class = Kernel.const_get( mixin_class_str )
|
42
|
+
# puts mixin_class.to_s
|
43
|
+
|
44
|
+
target_class.send( :include, mixin_class )
|
13
45
|
end
|
14
46
|
|
15
47
|
|
48
|
+
|
49
|
+
# for fil in ["string", "array", "false", "hash", "nil", "object",]
|
50
|
+
# require_relative File.join( "fun_with", "files", "core_extensions", fil )
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# for klass in ["String", "Object", "NilClass", "Hash", "FalseClass", "Array", "Set"]
|
54
|
+
# puts klass
|
55
|
+
# debugger if klass == "Set"
|
56
|
+
# Kernel.const_get(klass).send( :include, FunWith::Files::CoreExtensions.const_get(klass))
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
|
16
60
|
for fil in ["file_path", "string_behavior", "file_manipulation_methods", "file_permission_methods", "digest_methods", "file_requirements"]
|
17
61
|
require_relative File.join( "fun_with", "files", fil )
|
18
62
|
end
|
data/test/test_descent.rb
CHANGED
@@ -7,11 +7,11 @@ class TestDescent < FunWith::Files::TestCase
|
|
7
7
|
ascent = []
|
8
8
|
descent = []
|
9
9
|
|
10
|
-
|
10
|
+
root.ascend do |path|
|
11
11
|
ascent << path
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
root.descend do |path|
|
15
15
|
descent << path
|
16
16
|
end
|
17
17
|
|
@@ -54,7 +54,7 @@ class TestDirectoryBuilder < FunWith::Files::TestCase
|
|
54
54
|
gemfile = b.current_path.join("Gemfile")
|
55
55
|
assert gemfile.exist?
|
56
56
|
assert !gemfile.zero?
|
57
|
-
assert_equal 1, gemfile.grep( /
|
57
|
+
assert_equal 1, gemfile.grep( /juwelier/ ).length
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -72,7 +72,7 @@ class TestDirectoryBuilder < FunWith::Files::TestCase
|
|
72
72
|
DirectoryBuilder.tmpdir do |b|
|
73
73
|
gist_url = "http://bannedsorcery.com/downloads/testfile.txt"
|
74
74
|
gist_text = "This is a file\n==============\n\n**silent**: But _bold_! [Link](http://slashdot.org)\n"
|
75
|
-
b.download( gist_url, "gist.txt" )
|
75
|
+
b.download( gist_url, "gist.txt", :md5 => "f498e76ea5690a4c29ef97d0a1d8e58e", :sha1 => "ccabf74107cba7ad69f70e45c04c3876e7f34630" )
|
76
76
|
|
77
77
|
b.file( "gist.txt.2" ) do
|
78
78
|
b.download( gist_url )
|
@@ -13,7 +13,7 @@ class TestFileManipulation < FunWith::Files::TestCase
|
|
13
13
|
|
14
14
|
should "copy LICENSE.txt" do
|
15
15
|
copied = @license.cp( "test", "tmp" )
|
16
|
-
assert_match /LICENSE\.txt/, copied.to_s
|
16
|
+
assert_match( /LICENSE\.txt/, copied.to_s )
|
17
17
|
assert_file copied
|
18
18
|
assert_file_has_content copied
|
19
19
|
end
|
@@ -120,7 +120,7 @@ class TestFileManipulation < FunWith::Files::TestCase
|
|
120
120
|
|
121
121
|
file_def = file_abc.cp( dir_def )
|
122
122
|
|
123
|
-
assert_match /abc\.txt/, file_def.path
|
123
|
+
assert_match( /abc\.txt/, file_def.path )
|
124
124
|
assert_file_contents file_def, /rent/
|
125
125
|
|
126
126
|
|
data/test/test_file_path.rb
CHANGED
@@ -32,7 +32,7 @@ class TestFilePath < FunWith::Files::TestCase
|
|
32
32
|
assert_equal root, f1.up.up.up.up.up.up.up
|
33
33
|
|
34
34
|
#invoking up didn't change original
|
35
|
-
assert_match /ask_for_floyd/, f1.to_s
|
35
|
+
assert_match( /ask_for_floyd/, f1.to_s )
|
36
36
|
|
37
37
|
assert_equal f1, f2.down( "monkeylips" ).down( "ask_for_floyd" )
|
38
38
|
assert_equal f1, f2.down( "monkeylips", "ask_for_floyd" )
|
@@ -216,34 +216,82 @@ class TestFilePath < FunWith::Files::TestCase
|
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
219
|
-
context "
|
219
|
+
context "testing extension methods" do
|
220
220
|
setup do
|
221
|
-
@
|
221
|
+
@hello_path = "hello.txt".fwf_filepath
|
222
|
+
@dot_path0 = ".config".fwf_filepath
|
223
|
+
@dot_path1 = "~/.ssh".fwf_filepath
|
222
224
|
end
|
223
225
|
|
224
|
-
|
225
|
-
assert_equal @path.path, @path.ext( nil ).path
|
226
|
-
end
|
226
|
+
context "test ext()" do
|
227
227
|
|
228
|
-
|
229
|
-
|
230
|
-
|
228
|
+
should "not change path when sent nil as an argument" do
|
229
|
+
assert_equal @hello_path.path, @hello_path.ext( nil ).path
|
230
|
+
end
|
231
231
|
|
232
|
-
|
233
|
-
|
234
|
-
|
232
|
+
should "append when given symbol" do
|
233
|
+
assert_equal @hello_path.path + ".tgz", @hello_path.ext( :tgz ).path
|
234
|
+
end
|
235
|
+
|
236
|
+
should "append when given string" do
|
237
|
+
assert_equal @hello_path.path + ".tgz", @hello_path.ext( 'tgz' ).path
|
238
|
+
end
|
239
|
+
|
240
|
+
should "append correctly when given leading ." do
|
241
|
+
assert_equal @hello_path.path + ".tgz", @hello_path.ext( '.tgz' ).path
|
242
|
+
end
|
235
243
|
|
236
|
-
|
237
|
-
|
244
|
+
should "append multiple extensions as separate args" do
|
245
|
+
assert_equal @hello_path.path + ".backup.tar.gz", @hello_path.ext( :backup, "tar", nil, ".gz" ).path
|
246
|
+
end
|
247
|
+
|
248
|
+
should "append multiple extensions as a single string" do
|
249
|
+
assert_equal @hello_path.path + ".backup.tar.gz", @hello_path.ext( ".backup.tar.gz" ).path
|
250
|
+
end
|
238
251
|
end
|
239
252
|
|
240
|
-
|
241
|
-
|
253
|
+
context "test without_ext()" do
|
254
|
+
setup do
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
should "pop the extension (normal)" do
|
259
|
+
#debugger
|
260
|
+
assert_equal "hello", @hello_path.without_ext.to_s
|
261
|
+
assert_equal "hello", @hello_path.without_ext("txt").path
|
262
|
+
assert_equal "hello", @hello_path.without_ext(".txt").path
|
263
|
+
assert_equal "hello.txt", @hello_path.without_ext(".html").path
|
264
|
+
assert_equal "hello.txt", @hello_path.without_ext("html").path
|
265
|
+
|
266
|
+
assert_equal "hello", @hello_path.without_ext(:txt).path
|
267
|
+
end
|
268
|
+
|
269
|
+
should "not affect dot files" do
|
270
|
+
assert_equal ".config", @dot_path0.without_ext.path
|
271
|
+
assert_equal ".config", @dot_path0.without_ext("config").path
|
272
|
+
assert_equal ".config", @dot_path0.without_ext(".config").path
|
273
|
+
assert_equal ".config", @dot_path0.without_ext(:config).path
|
274
|
+
end
|
242
275
|
end
|
243
276
|
|
244
|
-
|
245
|
-
|
277
|
+
# Why does it return a filepath for the dirname piece, strings for the other two pieces?
|
278
|
+
context "test dirname_and_basename_and_ext" do
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
context "test join()" do
|
283
|
+
setup do
|
284
|
+
@path = "/".fwf_filepath
|
246
285
|
end
|
247
286
|
|
287
|
+
should "accept all manner of arguments" do
|
288
|
+
expected = "/bin/0/file.rb".fwf_filepath
|
289
|
+
result = @path.join( :bin, 0, "file.rb" )
|
290
|
+
|
291
|
+
assert_equal expected, result
|
292
|
+
|
293
|
+
result = @path / :bin / 0 / "file.rb"
|
294
|
+
assert_equal expected, result
|
295
|
+
end
|
248
296
|
end
|
249
297
|
end
|
data/test/test_fun_with_files.rb
CHANGED
@@ -26,7 +26,7 @@ class TestFunWithFiles < FunWith::Files::TestCase
|
|
26
26
|
assert_respond_to( FunWith::Files, :root )
|
27
27
|
assert_respond_to( FunWith::Files, :version )
|
28
28
|
|
29
|
-
assert_equal "0.0.
|
29
|
+
assert_equal "0.0.14", FunWith::Files.version # Gotta change with every point release. Ick.
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xdg
|
@@ -28,6 +28,9 @@ dependencies:
|
|
28
28
|
name: fun_with_testing
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.5
|
31
34
|
- - "~>"
|
32
35
|
- !ruby/object:Gem::Version
|
33
36
|
version: '0.0'
|
@@ -35,6 +38,9 @@ dependencies:
|
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.0.5
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '0.0'
|
@@ -59,12 +65,14 @@ extra_rdoc_files:
|
|
59
65
|
- README.rdoc
|
60
66
|
files:
|
61
67
|
- "./lib/fun_with/files/core_extensions/array.rb"
|
62
|
-
- "./lib/fun_with/files/core_extensions/
|
68
|
+
- "./lib/fun_with/files/core_extensions/false_class.rb"
|
63
69
|
- "./lib/fun_with/files/core_extensions/file.rb"
|
64
70
|
- "./lib/fun_with/files/core_extensions/hash.rb"
|
65
|
-
- "./lib/fun_with/files/core_extensions/
|
71
|
+
- "./lib/fun_with/files/core_extensions/nil_class.rb"
|
66
72
|
- "./lib/fun_with/files/core_extensions/object.rb"
|
73
|
+
- "./lib/fun_with/files/core_extensions/set.rb"
|
67
74
|
- "./lib/fun_with/files/core_extensions/string.rb"
|
75
|
+
- "./lib/fun_with/files/core_extensions/true_class.rb"
|
68
76
|
- "./lib/fun_with/files/digest_methods.rb"
|
69
77
|
- "./lib/fun_with/files/directory_builder.rb"
|
70
78
|
- "./lib/fun_with/files/downloader.rb"
|
@@ -136,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
144
|
version: '0'
|
137
145
|
requirements: []
|
138
146
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.6.6
|
140
148
|
signing_key:
|
141
149
|
specification_version: 4
|
142
150
|
summary: A mashup of several File, FileUtils, and Dir class functions, with a peppy,
|