fun_with_files 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +15 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +79 -0
- data/VERSION +1 -0
- data/lib/files/file_path.rb +232 -0
- data/lib/files/remote_path.rb +7 -0
- data/lib/files/root_path.rb +26 -0
- data/lib/files/string_extensions.rb +5 -0
- data/lib/fun_with_files.rb +12 -0
- data/test/data/empty.txt +0 -0
- data/test/data/grep1.txt +0 -0
- data/test/data/grep2.txt +0 -0
- data/test/helper.rb +20 -0
- data/test/test_file_path.rb +62 -0
- data/test/test_root_path.rb +24 -0
- data/test/test_touching.rb +33 -0
- metadata +154 -0
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem "shoulda", ">= 0"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", "~> 1.3.0"
|
13
|
+
gem "jeweler", "~> 1.8.4"
|
14
|
+
gem "debugger"
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Bryce Anderson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= fun_with_files
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to fun_with_files
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 Bryce Anderson. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rake'
|
15
|
+
|
16
|
+
require 'jeweler'
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
19
|
+
gem.name = "fun_with_files"
|
20
|
+
gem.homepage = "http://github.com/darthschmoo/fun_with_files"
|
21
|
+
gem.license = "MIT"
|
22
|
+
gem.summary = "A mashup of several File, FileUtils, and Dir class functions, with a peppy, fun-loving syntax"
|
23
|
+
gem.description = <<-DESC
|
24
|
+
A more intuitive syntax for performing a variety of file actions. Examples:
|
25
|
+
"/".fwf_filepath.join('usr', 'bin', 'bash').touch
|
26
|
+
FunWith::Files::FilePath.home("Music").glob(:ext => "mp3", :recurse => true)
|
27
|
+
home = FunWith::Files::FilePath.home
|
28
|
+
home.touch( "Music", "CDs", "BubbleBoyTechnoRemixxxx2011", "01-jiggypalooza.mp3" )
|
29
|
+
home.touch_dir( "Music", "CDs", "ReggaeSmackdown2008" ) do |dir|
|
30
|
+
dir.touch( "liner_notes.txt" )
|
31
|
+
dir.touch( "cover.jpg" )
|
32
|
+
dir.touch( "01-tokin_by_the_sea.mp3" )
|
33
|
+
dir.touch( "02-tourists_be_crazy_mon.mp3" )
|
34
|
+
end
|
35
|
+
DESC
|
36
|
+
gem.email = "keeputahweird@gmail.com"
|
37
|
+
gem.authors = ["Bryce Anderson"]
|
38
|
+
# dependencies defined in Gemfile
|
39
|
+
|
40
|
+
|
41
|
+
gem.files = Dir.glob( File.join( ".", "*.rb" ) ) +
|
42
|
+
Dir.glob( File.join( ".", "lib", "**", "*.rb" ) ) +
|
43
|
+
Dir.glob( File.join( ".", "test", "**", "*" ) ) +
|
44
|
+
[ "Gemfile",
|
45
|
+
"Rakefile",
|
46
|
+
"LICENSE.txt",
|
47
|
+
"README.rdoc",
|
48
|
+
"VERSION",
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
Jeweler::RubygemsDotOrgTasks.new
|
53
|
+
|
54
|
+
require 'rake/testtask'
|
55
|
+
Rake::TestTask.new(:test) do |test|
|
56
|
+
test.libs << 'lib' << 'test'
|
57
|
+
test.pattern = 'test/**/test_*.rb'
|
58
|
+
test.verbose = true
|
59
|
+
end
|
60
|
+
|
61
|
+
# require 'rcov/rcovtask'
|
62
|
+
# Rcov::RcovTask.new do |test|
|
63
|
+
# test.libs << 'test'
|
64
|
+
# test.pattern = 'test/**/test_*.rb'
|
65
|
+
# test.verbose = true
|
66
|
+
# test.rcov_opts << '--exclude "gems/*"'
|
67
|
+
# end
|
68
|
+
|
69
|
+
task :default => :test
|
70
|
+
|
71
|
+
require 'rdoc/task'
|
72
|
+
Rake::RDocTask.new do |rdoc|
|
73
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
74
|
+
|
75
|
+
rdoc.rdoc_dir = 'rdoc'
|
76
|
+
rdoc.title = "fun_with_files #{version}"
|
77
|
+
rdoc.rdoc_files.include('README*')
|
78
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
79
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,232 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Files
|
3
|
+
class FilePath < Pathname
|
4
|
+
def initialize( *args )
|
5
|
+
super( File.join( *args ) )
|
6
|
+
end
|
7
|
+
|
8
|
+
# args implicitly joined to cwd
|
9
|
+
def self.cwd( *args )
|
10
|
+
Dir.pwd.fwf_filepath.join( *args )
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.pwd( *args )
|
14
|
+
self.cwd( *args )
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.tmpdir( &block )
|
18
|
+
if block_given?
|
19
|
+
Dir.mktmpdir do |d|
|
20
|
+
yield d.fwf_filepath
|
21
|
+
end
|
22
|
+
else
|
23
|
+
Dir.mktmpdir.fwf_filepath
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.home( *args )
|
28
|
+
Dir.home.fwf_filepath.join( *args )
|
29
|
+
end
|
30
|
+
|
31
|
+
def join( *args, &block )
|
32
|
+
if block_given?
|
33
|
+
yield self.class.new( super(*args) )
|
34
|
+
else
|
35
|
+
self.class.new( super(*args) )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
alias :exists? :exist?
|
40
|
+
|
41
|
+
def up
|
42
|
+
self.class.new( self.join("..") ).expand
|
43
|
+
end
|
44
|
+
|
45
|
+
alias :down :join
|
46
|
+
|
47
|
+
# opts:
|
48
|
+
# :flags => File::FNM_CASEFOLD
|
49
|
+
# File::FNM_DOTMATCH
|
50
|
+
# File::FNM_NOESCAPE
|
51
|
+
# File::FNM_PATHNAME
|
52
|
+
# File::FNM_SYSCASE
|
53
|
+
# See Dir documentation for details.
|
54
|
+
# Can be given as an integer: (File::FNM_DOTMATCH | File::FNM_NOESCAPE)
|
55
|
+
# or as an array: [File::FNM_CASEFOLD, File::FNM_DOTMATCH]
|
56
|
+
#
|
57
|
+
# :class => [self.class] The class of objects you want returned (String, FilePath, ClassLoader, etc.)
|
58
|
+
# Should probably be a subclass of FilePath or String. Class.initialize() must accept a string
|
59
|
+
# [representing a file path] as the sole argument.
|
60
|
+
#
|
61
|
+
# :recurse => [false]
|
62
|
+
#
|
63
|
+
# :ext => [] A single symbol, or a list containing strings/symbols representing file name extensions.
|
64
|
+
# No leading periods kthxbai.
|
65
|
+
# :sensitive => true : do a case sensitive search. I guess the default is an insensitive search, so
|
66
|
+
# the default behaves similarly on Windows and Unix. Not gonna fight it.
|
67
|
+
#
|
68
|
+
# :dots => true : include dotfiles. Does not include . and ..s unless you also
|
69
|
+
# specify the option :parent_and_current => true.
|
70
|
+
#
|
71
|
+
# If opts[:recurse] / opts[:ext] not given, the user can get the same
|
72
|
+
# results explicitly with arguments like .glob("**", "*.rb")
|
73
|
+
#
|
74
|
+
# :all : if :all is the only argument, this is the same as .glob("**", "*")
|
75
|
+
def glob( *args )
|
76
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
77
|
+
|
78
|
+
flags = case opts[:flags]
|
79
|
+
when NilClass
|
80
|
+
0
|
81
|
+
when Array # should be an array of integers
|
82
|
+
opts[:flags].inject(0) do |memo, obj|
|
83
|
+
memo | obj
|
84
|
+
end
|
85
|
+
when Integer
|
86
|
+
opts[:flags]
|
87
|
+
end
|
88
|
+
|
89
|
+
flags |= File::FNM_DOTMATCH if opts[:dots]
|
90
|
+
flags |= File::FNM_CASEFOLD if opts[:sensitive]
|
91
|
+
|
92
|
+
if args.first == :all
|
93
|
+
args = ["**", "*"]
|
94
|
+
else
|
95
|
+
recurser = opts[:recurse] ? "**" : nil
|
96
|
+
extensions = case opts[:ext]
|
97
|
+
when Symbol, String
|
98
|
+
"*.#{opts[:ext]}"
|
99
|
+
when Array
|
100
|
+
extensions = opts[:ext].map(&:to_s).join(',')
|
101
|
+
"*.{#{extensions}}"
|
102
|
+
when NilClass
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
|
106
|
+
args += [recurser, extensions]
|
107
|
+
args.compact!
|
108
|
+
end
|
109
|
+
|
110
|
+
opts[:class] ||= self.class
|
111
|
+
|
112
|
+
files = Dir.glob( self.join(*args), flags ).map{ |f| opts[:class].new(f) }
|
113
|
+
files.reject!{ |f| f.basename.to_s.match(/^\.{1,2}$/) } unless opts[:parent_and_current]
|
114
|
+
files
|
115
|
+
end
|
116
|
+
|
117
|
+
def expand
|
118
|
+
self.class.new( File.expand_path( self ) )
|
119
|
+
end
|
120
|
+
|
121
|
+
# Raises error if self is a file and args present.
|
122
|
+
# Raises error if the file is not accessible for writing, or cannot be created.
|
123
|
+
# attempts to create a directory
|
124
|
+
def touch( *args )
|
125
|
+
raise "Cannot create subdirectory to a file" if self.file? && args.length > 0
|
126
|
+
touched = self.join(*args)
|
127
|
+
dir_for_touched_file = case args.length
|
128
|
+
when 0
|
129
|
+
self.up
|
130
|
+
when 1
|
131
|
+
self
|
132
|
+
when 2..Infinity
|
133
|
+
self.join( *(args[0..-2] ) )
|
134
|
+
end
|
135
|
+
|
136
|
+
self.touch_dir( dir_for_touched_file ) unless dir_for_touched_file.directory?
|
137
|
+
FileUtils.touch( touched )
|
138
|
+
return touched
|
139
|
+
end
|
140
|
+
|
141
|
+
def touch_dir( *args, &block )
|
142
|
+
touched = self.join(*args)
|
143
|
+
if touched.directory?
|
144
|
+
FileUtils.touch( touched ) # update access time
|
145
|
+
else
|
146
|
+
FileUtils.mkdir_p( touched ) # create directory (and any needed parents)
|
147
|
+
end
|
148
|
+
|
149
|
+
yield touched if block_given?
|
150
|
+
return touched
|
151
|
+
end
|
152
|
+
|
153
|
+
def write( content = nil, &block )
|
154
|
+
File.open( self, "w" ) do |f|
|
155
|
+
f << content if content
|
156
|
+
if block_given?
|
157
|
+
yield f
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def append( content = nil, &block )
|
163
|
+
File.open( self, "a" ) do |f|
|
164
|
+
f << content if content
|
165
|
+
if block_given?
|
166
|
+
yield f
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def grep( regex )
|
172
|
+
return [] unless self.file?
|
173
|
+
matching = []
|
174
|
+
self.each_line do |line|
|
175
|
+
matching.push( line ) if line.match( regex )
|
176
|
+
end
|
177
|
+
matching
|
178
|
+
end
|
179
|
+
|
180
|
+
# Not the same as zero?
|
181
|
+
def empty?
|
182
|
+
raise Exceptions::FileDoesNotExist unless self.exist?
|
183
|
+
|
184
|
+
if self.file?
|
185
|
+
File.size( self ) == 0
|
186
|
+
elsif self.directory?
|
187
|
+
self.glob( "**", "*" ).length == 0
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Does not return a filepath
|
192
|
+
def basename_no_ext
|
193
|
+
self.basename.to_s.split(".")[0..-2].join(".")
|
194
|
+
end
|
195
|
+
|
196
|
+
def without_ext
|
197
|
+
self.gsub(/\.#{self.ext}$/, '')
|
198
|
+
end
|
199
|
+
|
200
|
+
# Does not return a filepath.
|
201
|
+
# Does not include leading period
|
202
|
+
def ext
|
203
|
+
split_basename = self.basename.to_s.split(".")
|
204
|
+
split_basename.length > 1 ? split_basename.last : ""
|
205
|
+
end
|
206
|
+
|
207
|
+
# given an ancestor dir, returns a relative path that takes you from
|
208
|
+
# the ancestor dir to the pathfile. TODO: expand to arbitrary paths, not
|
209
|
+
# just immediate ancestors. For example "/usr/bin/bash".relative_to("/usr/bin/zsh") => "." ?
|
210
|
+
# TODO: look at Pathname.relative_path_from. Might just want to alias.
|
211
|
+
def relative_to( ancestor_dir )
|
212
|
+
depth = ancestor_dir.to_s.split(File::SEPARATOR).length
|
213
|
+
relative_path = self.to_s.split(File::SEPARATOR)
|
214
|
+
relative_path[(depth)..-1].join(File::SEPARATOR).fwf_filepath
|
215
|
+
end
|
216
|
+
|
217
|
+
# gsub acts on the filepath, not the file contents
|
218
|
+
def gsub( *args )
|
219
|
+
self.to_s.gsub(*args).fwf_filepath
|
220
|
+
end
|
221
|
+
|
222
|
+
def gsub!( *args )
|
223
|
+
new_path = self.to_s.gsub(*args)
|
224
|
+
self.instance_variable_set(:@path, new_path)
|
225
|
+
end
|
226
|
+
|
227
|
+
def fwf_filepath
|
228
|
+
self
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Files
|
3
|
+
module RootPathExtensions
|
4
|
+
def root( *args )
|
5
|
+
if args.length > 0
|
6
|
+
args.unshift( @root_path )
|
7
|
+
FilePath.new( *args )
|
8
|
+
else
|
9
|
+
FilePath.new( @root_path )
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_root_path( path )
|
14
|
+
@root_path = FunWith::Files::FilePath.new( path )
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class RootPath
|
19
|
+
def self.rootify( target, path )
|
20
|
+
raise "#{target} already responds to :root" if target.respond_to?(:root)
|
21
|
+
target.extend( RootPathExtensions )
|
22
|
+
target.set_root_path( FilePath.new( path ) )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'pathname' #stdlib
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'debugger'
|
4
|
+
|
5
|
+
|
6
|
+
require_relative File.join("files", "file_path")
|
7
|
+
require_relative File.join("files", "root_path")
|
8
|
+
require_relative File.join("files", "remote_path")
|
9
|
+
require_relative File.join("files", "string_extensions")
|
10
|
+
|
11
|
+
FunWith::Files::RootPath.rootify( FunWith::Files, FunWith::Files::FilePath.new(__FILE__).dirname.up )
|
12
|
+
|
data/test/data/empty.txt
ADDED
File without changes
|
data/test/data/grep1.txt
ADDED
File without changes
|
data/test/data/grep2.txt
ADDED
File without changes
|
data/test/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
require 'shoulda'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
require 'fun_with_files'
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
include FunWith::Files
|
4
|
+
|
5
|
+
class TestFilePath < Test::Unit::TestCase
|
6
|
+
context "testing basics" do
|
7
|
+
setup do
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
should "initialize kindly" do
|
12
|
+
f1 = FilePath.new( "/", "bin", "bash" )
|
13
|
+
f2 = "/".fwf_filepath( "bin", "bash" )
|
14
|
+
assert f1.exist?
|
15
|
+
assert f2.exist?
|
16
|
+
end
|
17
|
+
|
18
|
+
should "go up/down when asked" do
|
19
|
+
f1 = FilePath.new( "/", "home", "users", "monkeylips", "ask_for_floyd" )
|
20
|
+
f2 = FilePath.new( "/", "home", "users" )
|
21
|
+
root = FilePath.new( "/" )
|
22
|
+
|
23
|
+
assert_equal f2, f1.up.up
|
24
|
+
assert_equal root, f1.up.up.up.up.up.up.up
|
25
|
+
|
26
|
+
#invoking up didn't change original
|
27
|
+
assert_match /ask_for_floyd/, f1.to_s
|
28
|
+
|
29
|
+
assert_equal f1, f2.down( "monkeylips" ).down( "ask_for_floyd" )
|
30
|
+
assert_equal f1, f2.down( "monkeylips", "ask_for_floyd" )
|
31
|
+
|
32
|
+
#invoking down didn't change original
|
33
|
+
assert_no_match /ask_for_floyd/, f2.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "test glob" do
|
38
|
+
setup do
|
39
|
+
@data_dir = FunWith::Files.root( 'test', 'data' )
|
40
|
+
end
|
41
|
+
|
42
|
+
should "glob items in test/data directory" do
|
43
|
+
files = @data_dir.glob(:all)
|
44
|
+
assert_equal 3, files.length
|
45
|
+
files = @data_dir.glob(:all, :flags => [File::FNM_DOTMATCH])
|
46
|
+
assert_equal 7, files.length
|
47
|
+
end
|
48
|
+
|
49
|
+
should "glob with case insensitive flag" do
|
50
|
+
files = @data_dir.glob("grep1.txt")
|
51
|
+
assert_equal 1, files.length
|
52
|
+
|
53
|
+
# TODO: Case sensitive search?
|
54
|
+
# files = @data_dir.glob("grep1.txt", :flags => [File::FNM_CASEFOLD])
|
55
|
+
# assert_equal 2, files.length
|
56
|
+
# files = @data_dir.glob("grep1.txt", :sensitive => true)
|
57
|
+
# assert_equal 2, files.length
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
include FunWith::Files
|
4
|
+
|
5
|
+
class TestRootPath < Test::Unit::TestCase
|
6
|
+
should "add a root to a module" do
|
7
|
+
mod = Module.new
|
8
|
+
path = File.join("/", "usr", "bin")
|
9
|
+
rootify_and_test( mod, path )
|
10
|
+
end
|
11
|
+
|
12
|
+
should "add a root to an object" do
|
13
|
+
obj = Object.new
|
14
|
+
path = File.join("/", "usr", "bin")
|
15
|
+
rootify_and_test( obj, path )
|
16
|
+
end
|
17
|
+
|
18
|
+
def rootify_and_test( obj, path )
|
19
|
+
RootPath.rootify( obj, path )
|
20
|
+
assert obj.respond_to?(:root)
|
21
|
+
assert obj.respond_to?(:set_root_path)
|
22
|
+
assert_equal path, obj.root.to_s
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
include FunWith::Files
|
4
|
+
|
5
|
+
class TestTouching < Test::Unit::TestCase
|
6
|
+
context "inside a tmpdir" do
|
7
|
+
setup do
|
8
|
+
@dir = FilePath.tmpdir
|
9
|
+
end
|
10
|
+
|
11
|
+
teardown do
|
12
|
+
FileUtils.rmtree( @dir )
|
13
|
+
end
|
14
|
+
|
15
|
+
should "touch a subdirectory" do
|
16
|
+
@subdir = @dir.touch_dir( "Movies", "Basketball", "Shaquille" )
|
17
|
+
assert_kind_of FilePath, @subdir
|
18
|
+
assert @subdir.directory?
|
19
|
+
assert_equal @dir, @subdir.up.up.up
|
20
|
+
|
21
|
+
@subdir_file = @dir.join( "Movies", "Basketball", "Shaquille", "JamNinja.m4v" ).touch
|
22
|
+
assert_kind_of FilePath, @subdir_file
|
23
|
+
assert @subdir_file.file?
|
24
|
+
assert_equal @dir, @subdir_file.dirname.up.up.up
|
25
|
+
end
|
26
|
+
|
27
|
+
should "accept touch_dir on existing directory" do
|
28
|
+
assert_nothing_raised do
|
29
|
+
@dir.touch_dir
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fun_with_files
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bryce Anderson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shoulda
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.3.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: debugger
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! " A more intuitive syntax for performing a variety of file actions.
|
95
|
+
Examples:\n \"/\".fwf_filepath.join('usr', 'bin', 'bash').touch\n FunWith::Files::FilePath.home(\"Music\").glob(:ext
|
96
|
+
=> \"mp3\", :recurse => true)\n home = FunWith::Files::FilePath.home\n home.touch(
|
97
|
+
\"Music\", \"CDs\", \"BubbleBoyTechnoRemixxxx2011\", \"01-jiggypalooza.mp3\" )\n
|
98
|
+
\ home.touch_dir( \"Music\", \"CDs\", \"ReggaeSmackdown2008\" ) do |dir|\n dir.touch(
|
99
|
+
\"liner_notes.txt\" )\n dir.touch( \"cover.jpg\" )\n dir.touch( \"01-tokin_by_the_sea.mp3\"
|
100
|
+
)\n dir.touch( \"02-tourists_be_crazy_mon.mp3\" )\n end\n"
|
101
|
+
email: keeputahweird@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files:
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.rdoc
|
107
|
+
files:
|
108
|
+
- ./lib/files/file_path.rb
|
109
|
+
- ./lib/files/remote_path.rb
|
110
|
+
- ./lib/files/root_path.rb
|
111
|
+
- ./lib/files/string_extensions.rb
|
112
|
+
- ./lib/fun_with_files.rb
|
113
|
+
- ./test/data/empty.txt
|
114
|
+
- ./test/data/grep1.txt
|
115
|
+
- ./test/data/grep2.txt
|
116
|
+
- ./test/helper.rb
|
117
|
+
- ./test/test_file_path.rb
|
118
|
+
- ./test/test_root_path.rb
|
119
|
+
- ./test/test_touching.rb
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.rdoc
|
123
|
+
- Rakefile
|
124
|
+
- VERSION
|
125
|
+
homepage: http://github.com/darthschmoo/fun_with_files
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
hash: -1077870850940227410
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
143
|
+
requirements:
|
144
|
+
- - ! '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 1.8.25
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: A mashup of several File, FileUtils, and Dir class functions, with a peppy,
|
153
|
+
fun-loving syntax
|
154
|
+
test_files: []
|