fun_with_files 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/VERSION +1 -1
- data/lib/files/file_path.rb +31 -1
- data/lib/fun_with_files.rb +6 -9
- data/test/helper.rb +3 -0
- data/test/loadable_dir/dir1/file1.rb +7 -0
- data/test/loadable_dir/dir2/file2.rb +7 -0
- data/test/loadable_dir/dir3/file3.rb +7 -0
- data/test/loadable_dir/dir4/file4.rb +7 -0
- data/test/test_file_path.rb +1 -1
- data/test/test_globbing.rb +13 -0
- data/test/test_loading.rb +29 -0
- data/test/test_root_path.rb +1 -1
- data/test/test_touching.rb +3 -2
- metadata +25 -19
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/files/file_path.rb
CHANGED
@@ -59,6 +59,7 @@ module FunWith
|
|
59
59
|
# [representing a file path] as the sole argument.
|
60
60
|
#
|
61
61
|
# :recurse => [false]
|
62
|
+
# :recursive (synonym for :recurse)
|
62
63
|
#
|
63
64
|
# :ext => [] A single symbol, or a list containing strings/symbols representing file name extensions.
|
64
65
|
# No leading periods kthxbai.
|
@@ -92,7 +93,7 @@ module FunWith
|
|
92
93
|
if args.first == :all
|
93
94
|
args = ["**", "*"]
|
94
95
|
else
|
95
|
-
recurser = opts[:recurse] ? "**" : nil
|
96
|
+
recurser = (opts[:recurse] || opts[:recursive]) ? "**" : nil
|
96
97
|
extensions = case opts[:ext]
|
97
98
|
when Symbol, String
|
98
99
|
"*.#{opts[:ext]}"
|
@@ -330,6 +331,35 @@ module FunWith
|
|
330
331
|
def rename_all( pattern, gsubbed )
|
331
332
|
|
332
333
|
end
|
334
|
+
|
335
|
+
def rm( secure = false )
|
336
|
+
if self.file?
|
337
|
+
FileUtils.rm( self )
|
338
|
+
elsif self.directory?
|
339
|
+
FileUtils.rmtree( self )
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
def =~( rval )
|
344
|
+
self.to_s =~ rval
|
345
|
+
end
|
346
|
+
|
347
|
+
def load
|
348
|
+
if self.directory?
|
349
|
+
self.glob( :recursive => true, :ext => "rb" ).map(&:load)
|
350
|
+
else
|
351
|
+
Kernel.load( self.expand )
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
|
356
|
+
def requir
|
357
|
+
if self.directory?
|
358
|
+
self.glob( :recursive => true, :ext => "rb" ).map(&:requir)
|
359
|
+
else
|
360
|
+
require self.expand.gsub( /\.rb$/, '' )
|
361
|
+
end
|
362
|
+
end
|
333
363
|
end
|
334
364
|
end
|
335
365
|
end
|
data/lib/fun_with_files.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'pathname' #stdlib
|
2
2
|
require 'tmpdir'
|
3
|
-
require
|
3
|
+
require "debugger"
|
4
4
|
|
5
|
+
for file in %w(file_path root_path remote_path string_extensions pathname_extensions)
|
6
|
+
require_relative File.join("files", file)
|
7
|
+
end
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
require_relative File.join("files", "remote_path")
|
9
|
-
require_relative File.join("files", "string_extensions")
|
10
|
-
require_relative File.join("files", "pathname_extensions")
|
11
|
-
|
12
|
-
FunWith::Files::RootPath.rootify( FunWith::Files, FunWith::Files::FilePath.new(__FILE__).dirname.up )
|
13
|
-
|
9
|
+
FunWith::Files::RootPath.rootify( FunWith::Files, __FILE__.fwf_filepath.dirname.up )
|
10
|
+
FunWith::Files::VERSION = FunWith::Files.root("VERSION").read
|
data/test/helper.rb
CHANGED
data/test/test_file_path.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
include FunWith::Files
|
4
|
+
|
5
|
+
class TestGlobbing < FunWith::Files::TestCase
|
6
|
+
should "glob some ruby files from the test/loadable_dir directory" do
|
7
|
+
assert FunWith::Files.respond_to?(:root)
|
8
|
+
@loadable_dir = FunWith::Files.root("test", "loadable_dir")
|
9
|
+
assert @loadable_dir.directory?
|
10
|
+
@globs = @loadable_dir.glob( :recursive => true, :ext => "rb" )
|
11
|
+
assert_equal 4, @globs.length
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
include FunWith::Files
|
4
|
+
|
5
|
+
class TestLoading < FunWith::Files::TestCase
|
6
|
+
should "require a file" do
|
7
|
+
assert !defined?( LoadedOrRequiredModule::Loaded1 ), "LoadedOrRequiredModule::Loaded1 shouldn't be defined yet."
|
8
|
+
FunWith::Files.root( "test", "loadable_dir", "dir1", "file1.rb" ).requir
|
9
|
+
assert defined?( LoadedOrRequiredModule::Loaded1 ), "LoadedOrRequiredModule::Loaded1 should be defined now."
|
10
|
+
end
|
11
|
+
|
12
|
+
should "load a file" do
|
13
|
+
assert !defined?( LoadedOrRequiredModule::Loaded2 ), "LoadedOrRequiredModule::Loaded2 shouldn't be defined yet."
|
14
|
+
FunWith::Files.root( "test", "loadable_dir", "dir2", "file2.rb" ).load
|
15
|
+
assert defined?( LoadedOrRequiredModule::Loaded2 ), "LoadedOrRequiredModule::Loaded2 should be defined now."
|
16
|
+
end
|
17
|
+
|
18
|
+
should "require a directory" do
|
19
|
+
assert !defined?( LoadedOrRequiredModule::Loaded3 ), "LoadedOrRequiredModule::Loaded3 shouldn't be defined yet."
|
20
|
+
FunWith::Files.root( "test", "loadable_dir", "dir3" ).requir
|
21
|
+
assert defined?( LoadedOrRequiredModule::Loaded3 ), "LoadedOrRequiredModule::Loaded3 should be defined now."
|
22
|
+
end
|
23
|
+
|
24
|
+
should "load a directory" do
|
25
|
+
assert !defined?( LoadedOrRequiredModule::Loaded4 ), "LoadedOrRequiredModule::Loaded4 shouldn't be defined yet."
|
26
|
+
FunWith::Files.root( "test", "loadable_dir", "dir4" ).load
|
27
|
+
assert defined?( LoadedOrRequiredModule::Loaded4 ), "FunWith::Files::LoadedOrRequiredModule::Loaded4 should be defined now."
|
28
|
+
end
|
29
|
+
end
|
data/test/test_root_path.rb
CHANGED
data/test/test_touching.rb
CHANGED
@@ -2,14 +2,15 @@ require 'helper'
|
|
2
2
|
|
3
3
|
include FunWith::Files
|
4
4
|
|
5
|
-
class TestTouching <
|
5
|
+
class TestTouching < FunWith::Files::TestCase
|
6
6
|
context "inside a tmpdir" do
|
7
7
|
setup do
|
8
8
|
@dir = FilePath.tmpdir
|
9
9
|
end
|
10
10
|
|
11
11
|
teardown do
|
12
|
-
|
12
|
+
@dir.rm
|
13
|
+
assert_equal false, @dir.directory?
|
13
14
|
end
|
14
15
|
|
15
16
|
should "touch a subdirectory" do
|
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.4
|
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: 2013-
|
12
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: debugger
|
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: shoulda
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,22 +91,6 @@ dependencies:
|
|
75
91
|
- - ~>
|
76
92
|
- !ruby/object:Gem::Version
|
77
93
|
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
94
|
description: ! " A more intuitive syntax for performing a variety of file actions.
|
95
95
|
Examples:\n \"/\".fwf_filepath.join('usr', 'bin', 'bash').touch\n FunWith::Files::FilePath.home(\"Music\").glob(:ext
|
96
96
|
=> \"mp3\", :recurse => true)\n home = FunWith::Files::FilePath.home\n home.touch(
|
@@ -115,7 +115,13 @@ files:
|
|
115
115
|
- ./test/data/grep1.txt
|
116
116
|
- ./test/data/grep2.txt
|
117
117
|
- ./test/helper.rb
|
118
|
+
- ./test/loadable_dir/dir1/file1.rb
|
119
|
+
- ./test/loadable_dir/dir2/file2.rb
|
120
|
+
- ./test/loadable_dir/dir3/file3.rb
|
121
|
+
- ./test/loadable_dir/dir4/file4.rb
|
118
122
|
- ./test/test_file_path.rb
|
123
|
+
- ./test/test_globbing.rb
|
124
|
+
- ./test/test_loading.rb
|
119
125
|
- ./test/test_root_path.rb
|
120
126
|
- ./test/test_touching.rb
|
121
127
|
- Gemfile
|
@@ -138,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
144
|
version: '0'
|
139
145
|
segments:
|
140
146
|
- 0
|
141
|
-
hash: -
|
147
|
+
hash: -676116548205951635
|
142
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
149
|
none: false
|
144
150
|
requirements:
|