path 1.3.0
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/LICENSE +19 -0
- data/README.md +183 -0
- data/lib/epath.rb +2 -0
- data/lib/path.rb +159 -0
- data/lib/path/compatibility.rb +60 -0
- data/lib/path/dir.rb +147 -0
- data/lib/path/file.rb +132 -0
- data/lib/path/file_predicates.rb +151 -0
- data/lib/path/fileutils.rb +109 -0
- data/lib/path/find.rb +23 -0
- data/lib/path/identity.rb +163 -0
- data/lib/path/implementation.rb +294 -0
- data/lib/path/io.rb +104 -0
- data/lib/path/load.rb +29 -0
- data/lib/path/parts.rb +136 -0
- data/lib/path/predicates.rb +33 -0
- data/lib/path/require_tree.rb +42 -0
- data/lib/path/version.rb +5 -0
- data/path.gemspec +14 -0
- metadata +80 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
class Path
|
2
|
+
# @!group Path predicates
|
3
|
+
|
4
|
+
# Whether a path is absolute.
|
5
|
+
def absolute?
|
6
|
+
is_absolute?(@path)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Whether a path is relative.
|
10
|
+
def relative?
|
11
|
+
not absolute?
|
12
|
+
end
|
13
|
+
|
14
|
+
# #root? is a predicate for root directories. I.e. it returns +true+ if the
|
15
|
+
# path consists of consecutive slashes.
|
16
|
+
#
|
17
|
+
# It doesn't access actual filesystem. So it may return +false+ for some
|
18
|
+
# paths which points to roots such as +/usr/..+.
|
19
|
+
def root?
|
20
|
+
is_root?(@path)
|
21
|
+
end
|
22
|
+
|
23
|
+
# #mountpoint? returns +true+ if +self+ points to a mountpoint.
|
24
|
+
def mountpoint?
|
25
|
+
begin
|
26
|
+
stat1 = lstat
|
27
|
+
stat2 = parent.lstat
|
28
|
+
stat1.dev != stat2.dev or stat1.ino == stat2.ino
|
29
|
+
rescue Errno::ENOENT
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Path
|
2
|
+
# @!group Requiring
|
3
|
+
|
4
|
+
# Requires all .rb files recursively under +directory+
|
5
|
+
# (or the current file's directory if not given).
|
6
|
+
#
|
7
|
+
# The order of requires is alphabetical,
|
8
|
+
# but files having the same basename as a directory
|
9
|
+
# are required before files in this directory.
|
10
|
+
#
|
11
|
+
# # in bar.rb
|
12
|
+
# Path.require_tree
|
13
|
+
# # require in this order:
|
14
|
+
# # foo.rb
|
15
|
+
# # foo/ext.rb
|
16
|
+
# # foo/sub.rb
|
17
|
+
#
|
18
|
+
# @param directory [String] the directory to search,
|
19
|
+
# or the current file's directory.
|
20
|
+
# @option options [Array<String>] :except ([])
|
21
|
+
# a list of prefixes to ignore, relative to +directory+.
|
22
|
+
def self.require_tree(directory = nil, options = {})
|
23
|
+
directory, options = nil, directory if Hash === directory
|
24
|
+
source = Path.file(caller)
|
25
|
+
directory = Path.relative(directory || source.dir, caller)
|
26
|
+
except = options[:except] || []
|
27
|
+
|
28
|
+
directory.glob('**/*.rb').reject { |path|
|
29
|
+
except.any? { |prefix| (path % directory).path.start_with?(prefix) }
|
30
|
+
}.sort! { |a,b|
|
31
|
+
if b.inside?(a.rm_ext)
|
32
|
+
-1
|
33
|
+
elsif a.inside?(b.rm_ext)
|
34
|
+
+1
|
35
|
+
else
|
36
|
+
a <=> b
|
37
|
+
end
|
38
|
+
}.each { |file|
|
39
|
+
require file.path unless source == file
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
data/lib/path/version.rb
ADDED
data/path.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../lib/path/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'path'
|
5
|
+
s.summary = 'The Path manipulation library'
|
6
|
+
s.description = 'Path is a library to easily manage paths and with a lot of extra goodness.'
|
7
|
+
s.author = 'eregon'
|
8
|
+
s.email = 'eregontp@gmail.com'
|
9
|
+
s.homepage = 'https://github.com/eregon/path'
|
10
|
+
s.files = Dir['lib/**/*.rb'] + %w[README.md LICENSE path.gemspec]
|
11
|
+
s.version = Path::VERSION
|
12
|
+
|
13
|
+
s.add_development_dependency 'rspec'
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: path
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- eregon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
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
|
+
description: Path is a library to easily manage paths and with a lot of extra goodness.
|
31
|
+
email: eregontp@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/epath.rb
|
37
|
+
- lib/path/compatibility.rb
|
38
|
+
- lib/path/dir.rb
|
39
|
+
- lib/path/file.rb
|
40
|
+
- lib/path/file_predicates.rb
|
41
|
+
- lib/path/fileutils.rb
|
42
|
+
- lib/path/find.rb
|
43
|
+
- lib/path/identity.rb
|
44
|
+
- lib/path/implementation.rb
|
45
|
+
- lib/path/io.rb
|
46
|
+
- lib/path/load.rb
|
47
|
+
- lib/path/parts.rb
|
48
|
+
- lib/path/predicates.rb
|
49
|
+
- lib/path/require_tree.rb
|
50
|
+
- lib/path/version.rb
|
51
|
+
- lib/path.rb
|
52
|
+
- README.md
|
53
|
+
- LICENSE
|
54
|
+
- path.gemspec
|
55
|
+
homepage: https://github.com/eregon/path
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.23
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: The Path manipulation library
|
79
|
+
test_files: []
|
80
|
+
has_rdoc:
|