pathutil 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Rakefile +15 -0
- data/lib/pathutil.rb +60 -39
- data/lib/pathutil/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 669c8ad0cd1c1453270dc9f60b8cab8a1df7402b
|
4
|
+
data.tar.gz: 5e29a250d54e9aea640c556f929cc8b83940db71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19cebb9ac016da538e72374cba8c51f5d1a9f229e0cea0f022560257d6b96eac66a43d6a078c7fa7c9ef674df8768213df87950d1b60f489b91ab75f7a2b272c
|
7
|
+
data.tar.gz: 7d118f6675c9d116b5b5bc670c35fe79a8ba1cd62c0ccd815fb7c4011fb57c9a4eb08ed7a070855097a2fa00a154cbf81cd9fef262681ff084a1e90ff419e83a
|
data/Gemfile
CHANGED
@@ -14,6 +14,7 @@ end
|
|
14
14
|
group :development do
|
15
15
|
gem "rspec", :require => false
|
16
16
|
gem "rspec-helpers", :require => false
|
17
|
+
gem "luna-rubocop-formatters", :require => false
|
17
18
|
gem "rubocop", :github => "bbatsov/rubocop", :require => false
|
18
19
|
gem "luna-rspec-formatters", :require => false
|
19
20
|
gem "benchmark-ips", :require => false
|
data/Rakefile
CHANGED
@@ -14,6 +14,8 @@ RSpec::Core::RakeTask.new :spec
|
|
14
14
|
BenchmarkTask.new :benchmark
|
15
15
|
task :test => :spec
|
16
16
|
|
17
|
+
# ----------------------------------------------------------------------------
|
18
|
+
|
17
19
|
namespace :diff do
|
18
20
|
desc "List methods we have that Pathname doesn't."
|
19
21
|
task :methods do
|
@@ -24,6 +26,8 @@ namespace :diff do
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
29
|
+
# ----------------------------------------------------------------------------
|
30
|
+
|
27
31
|
namespace :missing do
|
28
32
|
desc "List methods we are missing."
|
29
33
|
task :methods do
|
@@ -38,6 +42,8 @@ namespace :missing do
|
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
45
|
+
# ----------------------------------------------------------------------------
|
46
|
+
|
41
47
|
namespace :pathname do
|
42
48
|
desc "List all of Pathnames methods."
|
43
49
|
task :methods do
|
@@ -53,6 +59,8 @@ namespace :pathname do
|
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
62
|
+
# ----------------------------------------------------------------------------
|
63
|
+
|
56
64
|
desc "List all of Pathutils methods."
|
57
65
|
task :methods do
|
58
66
|
methods = Pathutil.instance_methods - Object.instance_methods
|
@@ -63,3 +71,10 @@ task :methods do
|
|
63
71
|
|
64
72
|
$stdout.puts
|
65
73
|
end
|
74
|
+
|
75
|
+
# ----------------------------------------------------------------------------
|
76
|
+
|
77
|
+
task :rubocop do
|
78
|
+
sh "bundle", "exec", "rubocop", "-DE", "-r", "luna/rubocop/formatters/checks", \
|
79
|
+
"-f", "Luna::RuboCop::Formatters::Checks"
|
80
|
+
end
|
data/lib/pathutil.rb
CHANGED
@@ -11,42 +11,12 @@ require "find"
|
|
11
11
|
|
12
12
|
class Pathutil
|
13
13
|
extend Forwardable::Extended
|
14
|
-
self.class.send(:attr_writer, :encoding)
|
15
14
|
attr_writer :encoding
|
16
15
|
|
17
|
-
#
|
18
|
-
|
19
|
-
class << self
|
20
|
-
|
21
|
-
# ------------------------------------------------------------------------
|
22
|
-
# Aliases the default system encoding to us so that we can do most read
|
23
|
-
# and write operations with that encoding, instead of being crazy.
|
24
|
-
# @note you are encouraged to override this if you need to.
|
25
|
-
# ------------------------------------------------------------------------
|
26
|
-
|
27
|
-
def encoding
|
28
|
-
return @encoding ||= begin
|
29
|
-
Encoding.default_external
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# ------------------------------------------------------------------------
|
34
|
-
# Normalize CRLF -> LF on Windows reads, to ease your troubles.
|
35
|
-
# Normalize LF -> CLRF on Windows write, to ease their troubles.
|
36
|
-
# ------------------------------------------------------------------------
|
37
|
-
|
38
|
-
def normalize
|
39
|
-
return @normalize ||= {
|
40
|
-
:read => Gem.win_platform?,
|
41
|
-
:write => Gem.win_platform?
|
42
|
-
}
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
16
|
# --------------------------------------------------------------------------
|
47
17
|
|
48
18
|
def initialize(path)
|
49
|
-
@path = path.respond_to?(:to_path) ? path.to_path : path.to_s
|
19
|
+
@path = (path.respond_to?(:to_path) ? path.to_path : path.to_s).dup
|
50
20
|
end
|
51
21
|
|
52
22
|
# --------------------------------------------------------------------------
|
@@ -92,7 +62,7 @@ class Pathutil
|
|
92
62
|
|
93
63
|
# --------------------------------------------------------------------------
|
94
64
|
|
95
|
-
def read_yaml(safe: true, whitelist_classes: [], throw_missing: false)
|
65
|
+
def read_yaml(safe: true, whitelist_classes: [], whitelist_symbols: [], throw_missing: false, aliases: true)
|
96
66
|
require "yaml"
|
97
67
|
|
98
68
|
unless safe
|
@@ -103,14 +73,17 @@ class Pathutil
|
|
103
73
|
|
104
74
|
if !YAML.respond_to?(:safe_load)
|
105
75
|
setup_safe_yaml whitelist_classes
|
106
|
-
SafeYAML.load(
|
107
|
-
|
108
|
-
|
76
|
+
SafeYAML.load(
|
77
|
+
read
|
78
|
+
)
|
109
79
|
|
110
80
|
else
|
111
|
-
YAML.safe_load(
|
112
|
-
|
113
|
-
|
81
|
+
YAML.safe_load(
|
82
|
+
read,
|
83
|
+
whitelist_classes,
|
84
|
+
whitelist_symbols,
|
85
|
+
aliases
|
86
|
+
)
|
114
87
|
end
|
115
88
|
rescue Errno::ENOENT
|
116
89
|
throw_missing ? raise : (
|
@@ -284,7 +257,12 @@ class Pathutil
|
|
284
257
|
# --------------------------------------------------------------------------
|
285
258
|
|
286
259
|
def descend
|
287
|
-
|
260
|
+
unless block_given?
|
261
|
+
return to_enum(
|
262
|
+
__method__
|
263
|
+
)
|
264
|
+
end
|
265
|
+
|
288
266
|
ascend.to_a.reverse_each do |val|
|
289
267
|
yield val
|
290
268
|
end
|
@@ -701,6 +679,49 @@ class Pathutil
|
|
701
679
|
|
702
680
|
# --------------------------------------------------------------------------
|
703
681
|
|
682
|
+
class << self
|
683
|
+
attr_writer :encoding
|
684
|
+
|
685
|
+
# ------------------------------------------------------------------------
|
686
|
+
# Aliases the default system encoding to us so that we can do most read
|
687
|
+
# and write operations with that encoding, instead of being crazy.
|
688
|
+
# @note you are encouraged to override this if you need to.
|
689
|
+
# ------------------------------------------------------------------------
|
690
|
+
|
691
|
+
def encoding
|
692
|
+
return @encoding ||= begin
|
693
|
+
Encoding.default_external
|
694
|
+
end
|
695
|
+
end
|
696
|
+
|
697
|
+
# ------------------------------------------------------------------------
|
698
|
+
# Normalize CRLF -> LF on Windows reads, to ease your troubles.
|
699
|
+
# Normalize LF -> CLRF on Windows write, to ease their troubles.
|
700
|
+
# ------------------------------------------------------------------------
|
701
|
+
|
702
|
+
def normalize
|
703
|
+
return @normalize ||= {
|
704
|
+
:read => Gem.win_platform?,
|
705
|
+
:write => Gem.win_platform?
|
706
|
+
}
|
707
|
+
end
|
708
|
+
|
709
|
+
# ------------------------------------------------------------------------
|
710
|
+
|
711
|
+
def make_tmpname(prefix = "", suffix = nil)
|
712
|
+
prefix = prefix.gsub(/\-\Z/, "") + "-" unless prefix.empty?
|
713
|
+
|
714
|
+
File.join(
|
715
|
+
Dir::Tmpname.tmpdir,
|
716
|
+
Dir::Tmpname.make_tmpname(
|
717
|
+
prefix, suffix
|
718
|
+
)
|
719
|
+
)
|
720
|
+
end
|
721
|
+
end
|
722
|
+
|
723
|
+
# --------------------------------------------------------------------------
|
724
|
+
|
704
725
|
rb_delegate :sub, :to => :@path, :wrap => true
|
705
726
|
rb_delegate :chomp, :to => :@path, :wrap => true
|
706
727
|
rb_delegate :gsub, :to => :@path, :wrap => true
|
data/lib/pathutil/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathutil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordon Bedwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwardable-extended
|