filepath 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ # This is free and unencumbered software released into the public domain.
2
+ # See the `UNLICENSE` file or <http://unlicense.org/> for more details.
3
+
4
+ require File.join(File.dirname(__FILE__), 'spec_helper')
5
+
6
+ describe FilePathList do
7
+ describe "#/" do
8
+ it "adds the same string to all the paths" do
9
+ list = FilePathList.new(%w{foo faa}) / 'bar'
10
+ list[0].should eq 'foo/bar'
11
+ list[1].should eq 'faa/bar'
12
+ end
13
+ end
14
+
15
+ describe "#*" do
16
+ describe "calculates the cartesian product between" do
17
+ it "two FilePathLists" do
18
+ p1 = %w{a b c}
19
+ p2 = %w{1 2}
20
+ list1 = FilePathList.new(p1)
21
+ list2 = FilePathList.new(p2)
22
+
23
+ all_paths = p1.product(p2).map { |x| x.join('/') }
24
+
25
+ list = list1 * list2
26
+ list.should have(6).items
27
+ list.should include(*all_paths)
28
+ end
29
+
30
+ it "a FilePathList and a string" do
31
+ p1 = %w{a b c}
32
+ p2 = "abc"
33
+
34
+ list = FilePathList.new(p1) * p2
35
+ list.should have(3).items
36
+ list.should include(*%w{a/abc b/abc c/abc})
37
+ end
38
+
39
+ it "a FilePathList and a FilePath" do
40
+ p1 = %w{a b c}
41
+ p2 = FilePath.new("x")
42
+
43
+ list = FilePathList.new(p1) * p2
44
+ list.should have(3).items
45
+ list.should include(*%w{a/x b/x c/x})
46
+ end
47
+
48
+ it "a FilePath and an array of strings" do
49
+ p1 = %w{a b c}
50
+ p2 = ["1", "2"]
51
+
52
+ list = FilePathList.new(p1) * p2
53
+ list.should have(6).items
54
+ list.should include(*%w{a/1 b/1 a/2 b/2 c/1 c/2})
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "#include?" do
60
+ it "says that `a/c` in included in [<a/b>, <a/c>, </a/d>]" do
61
+ list = FilePathList.new(%w{a/b a/c /a/d})
62
+ list.should include("a/c")
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,10 @@
1
+ LIB_DIR = File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
2
+ $LOAD_PATH.unshift(LIB_DIR) unless $LOAD_PATH.include?(LIB_DIR)
3
+
4
+ require 'filepath'
5
+ require 'filepathlist'
6
+
7
+ RSpec.configure do |config|
8
+ end
9
+
10
+ FIXTURES_DIR = File.join(%w{spec fixtures})
@@ -0,0 +1,40 @@
1
+ # This is free and unencumbered software released into the public domain.
2
+ # See the `UNLICENSE` file or <http://unlicense.org/> for more details.
3
+
4
+ FIXTURES_DIR = File.join(%w{spec fixtures})
5
+ FIXTURES_FAKE_ENTRIES = [
6
+ 'd1',
7
+ ['d1', 'd11'],
8
+ ['d1', 'd12'],
9
+ ['d1', 'd13'],
10
+ ['d1', 'f11'],
11
+ ['d1', 'f12'],
12
+ ['d1', 'l11'],
13
+ 'd2',
14
+ ['d2', 'd21'],
15
+ ['d2', 'd22'],
16
+ 'd3',
17
+ 'f1',
18
+ 'dx',
19
+ ].map { |entry| File.join(FIXTURES_DIR, *Array(entry)) }
20
+
21
+ CLEAN.concat FIXTURES_FAKE_ENTRIES
22
+
23
+ namespace :spec do
24
+ namespace :fixtures do
25
+ rule %r{/d[0-9x]+$} do |t|
26
+ mkdir_p t.name
27
+ end
28
+
29
+ rule %r{/f[0-9]+$} do |t|
30
+ touch t.name
31
+ end
32
+
33
+ rule %r{/l[0-9]+$} do |t|
34
+ ln_s '/dev/null', t.name
35
+ end
36
+
37
+ desc "Generate fake dirs and files"
38
+ task :gen => FIXTURES_FAKE_ENTRIES
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filepath
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gioele Barabucci
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bones
16
+ requirement: &14096440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.7.3
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *14096440
25
+ description: ! '`FilePath` is a class that helps dealing with files, directories and
26
+ paths in
27
+
28
+ general; a modern replacement for the standard Pathname.'
29
+ email: gioele@svario.it
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - .yardopts
36
+ - README.md
37
+ - Rakefile
38
+ - UNLICENSE
39
+ - lib/filepath.rb
40
+ - lib/filepathlist.rb
41
+ - spec/filepath_spec.rb
42
+ - spec/filepathlist_spec.rb
43
+ - spec/spec_helper.rb
44
+ - spec/tasks.rb
45
+ homepage: http://github.com/gioele/filepath
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --main
50
+ - README.md
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project: filepath
67
+ rubygems_version: 1.8.12
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: ! '`FilePath` is a class that helps dealing with files, directories and paths
71
+ in general; a modern replacement for the standard Pathname.'
72
+ test_files: []