berkeley_library-util 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/util.iml +39 -36
- data/CHANGES.md +4 -0
- data/README.md +4 -0
- data/lib/berkeley_library/util/files.rb +37 -0
- data/lib/berkeley_library/util/module_info.rb +2 -4
- data/spec/berkeley_library/util/files_spec.rb +115 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b313922bbe999c373d0094a01734c05aa0e31606aeef894bb0503293a8c78e65
|
4
|
+
data.tar.gz: f7e67788b3b88035ff9feac00386d45cf5e35b92c5a25a40d311fe8df16e3056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 711daf87bdb397f89302d6ee5c9f00464863947e2d7bd5d24736de48acbe987096b59d814638d4ad2e897f5bf48fc2d1e5037b753c0405c597c6feda39ba1a81
|
7
|
+
data.tar.gz: dfb544c71430fbda524e3ca4b8ca32d5387fb55683cd6a2eefebaceb6152416afb5d72dae03dc5a2636b3dde4f4be8a5e49695a358a4a4348ff16dc38f3cadf9
|
data/.idea/util.iml
CHANGED
@@ -1,28 +1,31 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
3
6
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
7
|
<exclude-output />
|
5
8
|
<content url="file://$MODULE_DIR$" />
|
6
9
|
<orderEntry type="jdk" jdkName="RVM: ruby-2.7.4" jdkType="RUBY_SDK" />
|
7
10
|
<orderEntry type="sourceFolder" forTests="false" />
|
8
|
-
<orderEntry type="library" scope="PROVIDED" name="actionpack (
|
9
|
-
<orderEntry type="library" scope="PROVIDED" name="actionview (
|
10
|
-
<orderEntry type="library" scope="PROVIDED" name="activesupport (
|
11
|
+
<orderEntry type="library" scope="PROVIDED" name="actionpack (v7.0.2.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
12
|
+
<orderEntry type="library" scope="PROVIDED" name="actionview (v7.0.2.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
13
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v7.0.2.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
11
14
|
<orderEntry type="library" scope="PROVIDED" name="addressable (v2.8.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
12
|
-
<orderEntry type="library" scope="PROVIDED" name="amazing_print (v1.
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="amazing_print (v1.4.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
13
16
|
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-logging (v0.2.
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-logging (v0.2.6, RVM: ruby-2.7.4) [gem]" level="application" />
|
15
18
|
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
16
19
|
<orderEntry type="library" scope="PROVIDED" name="bundle-audit (v0.1.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
17
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.31, RVM: ruby-2.7.4) [gem]" level="application" />
|
18
21
|
<orderEntry type="library" scope="PROVIDED" name="bundler-audit (v0.9.0.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
19
22
|
<orderEntry type="library" scope="PROVIDED" name="ci_reporter (v2.0.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
20
23
|
<orderEntry type="library" scope="PROVIDED" name="ci_reporter_rspec (v1.0.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
21
24
|
<orderEntry type="library" scope="PROVIDED" name="colorize (v0.8.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
22
|
-
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.10, RVM: ruby-2.7.4) [gem]" level="application" />
|
23
26
|
<orderEntry type="library" scope="PROVIDED" name="crack (v0.4.5, RVM: ruby-2.7.4) [gem]" level="application" />
|
24
27
|
<orderEntry type="library" scope="PROVIDED" name="crass (v1.0.6, RVM: ruby-2.7.4) [gem]" level="application" />
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
26
29
|
<orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
27
30
|
<orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.20190701, RVM: ruby-2.7.4) [gem]" level="application" />
|
28
31
|
<orderEntry type="library" scope="PROVIDED" name="dotenv (v2.7.6, RVM: ruby-2.7.4) [gem]" level="application" />
|
@@ -30,55 +33,55 @@
|
|
30
33
|
<orderEntry type="library" scope="PROVIDED" name="hashdiff (v1.0.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
31
34
|
<orderEntry type="library" scope="PROVIDED" name="http-accept (v1.7.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
32
35
|
<orderEntry type="library" scope="PROVIDED" name="http-cookie (v1.0.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
33
|
-
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.
|
34
|
-
<orderEntry type="library" scope="PROVIDED" name="lograge (v0.
|
35
|
-
<orderEntry type="library" scope="PROVIDED" name="loofah (v2.
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.10.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="lograge (v0.12.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="loofah (v2.17.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
36
39
|
<orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
37
|
-
<orderEntry type="library" scope="PROVIDED" name="mime-types (v3.
|
38
|
-
<orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.
|
39
|
-
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="mime-types (v3.4.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2022.0105, RVM: ruby-2.7.4) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
40
43
|
<orderEntry type="library" scope="PROVIDED" name="netrc (v0.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
41
|
-
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.
|
42
|
-
<orderEntry type="library" scope="PROVIDED" name="oj (v3.13.
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.13.5, RVM: ruby-2.7.4) [gem]" level="application" />
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="oj (v3.13.11, RVM: ruby-2.7.4) [gem]" level="application" />
|
43
46
|
<orderEntry type="library" scope="PROVIDED" name="ougai (v1.9.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
44
|
-
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.
|
45
|
-
<orderEntry type="library" scope="PROVIDED" name="parser (v3.
|
46
|
-
<orderEntry type="library" scope="PROVIDED" name="public_suffix (v4.0.
|
47
|
-
<orderEntry type="library" scope="PROVIDED" name="racc (v1.
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
49
|
+
<orderEntry type="library" scope="PROVIDED" name="public_suffix (v4.0.7, RVM: ruby-2.7.4) [gem]" level="application" />
|
50
|
+
<orderEntry type="library" scope="PROVIDED" name="racc (v1.6.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
48
51
|
<orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, RVM: ruby-2.7.4) [gem]" level="application" />
|
49
52
|
<orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
50
53
|
<orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, RVM: ruby-2.7.4) [gem]" level="application" />
|
51
54
|
<orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.4.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
52
|
-
<orderEntry type="library" scope="PROVIDED" name="railties (
|
53
|
-
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.
|
55
|
+
<orderEntry type="library" scope="PROVIDED" name="railties (v7.0.2.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
56
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
54
57
|
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-2.7.4) [gem]" level="application" />
|
55
|
-
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.
|
56
|
-
<orderEntry type="library" scope="PROVIDED" name="request_store (v1.5.
|
58
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.3.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
59
|
+
<orderEntry type="library" scope="PROVIDED" name="request_store (v1.5.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
57
60
|
<orderEntry type="library" scope="PROVIDED" name="rest-client (v2.1.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
58
61
|
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, RVM: ruby-2.7.4) [gem]" level="application" />
|
59
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.
|
60
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.
|
61
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.
|
62
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.
|
63
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.
|
62
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
63
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
64
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
65
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.11.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
66
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
64
67
|
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
65
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.
|
68
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.17.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
66
69
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-rake (v0.6.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
67
70
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v2.4.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
68
71
|
<orderEntry type="library" scope="PROVIDED" name="ruby-prof (v0.17.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
69
72
|
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
70
73
|
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.21.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
71
74
|
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.3, RVM: ruby-2.7.4) [gem]" level="application" />
|
72
|
-
<orderEntry type="library" scope="PROVIDED" name="simplecov-rcov (v0.
|
73
|
-
<orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.
|
74
|
-
<orderEntry type="library" scope="PROVIDED" name="thor (v1.1
|
75
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov-rcov (v0.3.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
76
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
77
|
+
<orderEntry type="library" scope="PROVIDED" name="thor (v1.2.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
75
78
|
<orderEntry type="library" scope="PROVIDED" name="typesafe_enum (v0.3.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
76
79
|
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
77
80
|
<orderEntry type="library" scope="PROVIDED" name="unf (v0.1.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
78
|
-
<orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.8, RVM: ruby-2.7.4) [gem]" level="application" />
|
81
|
+
<orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.8.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
79
82
|
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
80
83
|
<orderEntry type="library" scope="PROVIDED" name="webmock (v3.14.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
81
|
-
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.4
|
84
|
+
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.5.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
82
85
|
</component>
|
83
86
|
<component name="RModuleSettingsStorage">
|
84
87
|
<LOAD_PATH number="2" string0="$MODULE_DIR$/lib" string1="$MODULE_DIR$/spec" />
|
@@ -95,7 +98,7 @@
|
|
95
98
|
</RakeTaskImpl>
|
96
99
|
<RakeTaskImpl description="Run all specs in spec directory, with coverage" fullCommand="coverage" id="coverage" />
|
97
100
|
<RakeTaskImpl description="Run tests, check test coverage, check code style, check for vulnerabilities, build gem" fullCommand="default" id="default" />
|
98
|
-
<RakeTaskImpl description="Build berkeley_library-util.gemspec as berkeley_library-util-0.1.
|
101
|
+
<RakeTaskImpl description="Build berkeley_library-util.gemspec as berkeley_library-util-0.1.1.gem" fullCommand="gem" id="gem" />
|
99
102
|
<RakeTaskImpl description="Run RuboCop with auto-correct, and output results to console" fullCommand="ra" id="ra" />
|
100
103
|
<RakeTaskImpl description="Run rubocop with HTML output" fullCommand="rubocop" id="rubocop" />
|
101
104
|
<RakeTaskImpl id="rubocop">
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -19,3 +19,7 @@ Routines for modifying paths separated by forward slashes,
|
|
19
19
|
## [BerkeleyLibrary::Util::URIs](lib/berkeley_library/util/uris.rb)
|
20
20
|
|
21
21
|
Routines for constructing, validating, and retrieving the content from URIs.
|
22
|
+
|
23
|
+
## [BerkeleyLibrary::Util::Files](lib/berkeley_library/util/files.rb)
|
24
|
+
|
25
|
+
Routines for working with file paths and IO objects.
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module BerkeleyLibrary
|
2
|
+
module Util
|
3
|
+
module Files
|
4
|
+
class << self
|
5
|
+
include Files
|
6
|
+
end
|
7
|
+
|
8
|
+
def file_exists?(path)
|
9
|
+
(path.respond_to?(:exist?) && path.exist?) ||
|
10
|
+
(path.respond_to?(:to_str) && File.exist?(path))
|
11
|
+
end
|
12
|
+
|
13
|
+
def parent_exists?(path)
|
14
|
+
path.respond_to?(:parent) && path.parent.exist? ||
|
15
|
+
path.respond_to?(:to_str) && Pathname.new(path).parent.exist?
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns true if `obj` is close enough to an IO object for Nokogiri
|
19
|
+
# to parse as one.
|
20
|
+
#
|
21
|
+
# @param obj [Object] the object that might be an IO
|
22
|
+
# @see https://github.com/sparklemotion/nokogiri/blob/v1.11.1/lib/nokogiri/xml/sax/parser.rb#L81 Nokogiri::XML::SAX::Parser#parse
|
23
|
+
def reader_like?(obj)
|
24
|
+
obj.respond_to?(:read) && obj.respond_to?(:close)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns true if `obj` is close enough to an IO object for Nokogiri
|
28
|
+
# to write to.
|
29
|
+
#
|
30
|
+
# @param obj [Object] the object that might be an IO
|
31
|
+
def writer_like?(obj)
|
32
|
+
obj.respond_to?(:write) && obj.respond_to?(:close)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -5,11 +5,9 @@ module BerkeleyLibrary
|
|
5
5
|
AUTHOR = 'David Moles'.freeze
|
6
6
|
AUTHOR_EMAIL = 'dmoles@berkeley.edu'.freeze
|
7
7
|
SUMMARY = 'Miscellaneous Ruby utilities for the UC Berkeley Library'.freeze
|
8
|
-
DESCRIPTION =
|
9
|
-
A collection of miscellaneous Ruby routines for the UC Berkeley Library.
|
10
|
-
DESC
|
8
|
+
DESCRIPTION = 'A collection of miscellaneous Ruby routines for the UC Berkeley Library.'.freeze
|
11
9
|
LICENSE = 'MIT'.freeze
|
12
|
-
VERSION = '0.1.
|
10
|
+
VERSION = '0.1.2'.freeze
|
13
11
|
HOMEPAGE = 'https://github.com/BerkeleyLibrary/util'.freeze
|
14
12
|
end
|
15
13
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BerkeleyLibrary
|
4
|
+
module Util
|
5
|
+
describe Files do
|
6
|
+
let(:basename) { File.basename(__FILE__, '.rb') }
|
7
|
+
|
8
|
+
attr_reader :tmpdir
|
9
|
+
|
10
|
+
before { @tmpdir = Dir.mktmpdir(basename) }
|
11
|
+
after { FileUtils.remove_entry(tmpdir) }
|
12
|
+
|
13
|
+
describe :file_exists? do
|
14
|
+
it 'returns true for files that exist' do
|
15
|
+
path = Pathname.new(tmpdir).join('exists').tap { |p| FileUtils.touch(p) }
|
16
|
+
expect(path.exist?).to eq(true) # just to be sure
|
17
|
+
path_str = path.to_s
|
18
|
+
|
19
|
+
expect(Files.file_exists?(path)).to eq(true)
|
20
|
+
expect(Files.file_exists?(path_str)).to eq(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns false for files that do not exist' do
|
24
|
+
path = Pathname.new(tmpdir).join('not-exists')
|
25
|
+
expect(path.exist?).to eq(false) # just to be sure
|
26
|
+
path_str = path.to_s
|
27
|
+
|
28
|
+
expect(Files.file_exists?(path)).to eq(false)
|
29
|
+
expect(Files.file_exists?(path_str)).to eq(false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe :parent_exists? do
|
34
|
+
it 'returns true for paths whose parent exists' do
|
35
|
+
parent = Pathname.new(tmpdir).join('parent').tap(&:mkdir)
|
36
|
+
expect(parent.exist?).to eq(true) # just to be sure
|
37
|
+
path = parent.join('child')
|
38
|
+
path_str = path.to_s
|
39
|
+
|
40
|
+
expect(Files.parent_exists?(path)).to eq(true)
|
41
|
+
expect(Files.parent_exists?(path_str)).to eq(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns false for paths whose parent does not' do
|
45
|
+
parent = Pathname.new(tmpdir).join('parent')
|
46
|
+
expect(parent.exist?).to eq(false) # just to be sure
|
47
|
+
path = parent.join('child')
|
48
|
+
path_str = path.to_s
|
49
|
+
|
50
|
+
expect(Files.parent_exists?(path)).to eq(false)
|
51
|
+
expect(Files.parent_exists?(path_str)).to eq(false)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe :reader_like? do
|
56
|
+
it 'returns true for a readable file' do
|
57
|
+
filename = File.join(tmpdir, 'out')
|
58
|
+
FileUtils.touch(filename)
|
59
|
+
|
60
|
+
File.open(filename, 'rb') do |out|
|
61
|
+
expect(Files.reader_like?(out)).to eq(true)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns true for a StringIO' do
|
66
|
+
out = StringIO.new
|
67
|
+
expect(Files.reader_like?(out)).to eq(true)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns true for a Tempfile' do
|
71
|
+
out = Tempfile.new('out')
|
72
|
+
begin
|
73
|
+
expect(Files.reader_like?(out)).to eq(true)
|
74
|
+
ensure
|
75
|
+
out.close
|
76
|
+
out.unlink
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns false for something that is not reader-like' do
|
81
|
+
expect(Files.reader_like?('not an IO')).to eq(false)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe :writer_like? do
|
86
|
+
it 'returns true for a writable file' do
|
87
|
+
filename = File.join(tmpdir, 'out')
|
88
|
+
|
89
|
+
File.open(filename, 'wb') do |out|
|
90
|
+
expect(Files.writer_like?(out)).to eq(true)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns true for a StringIO' do
|
95
|
+
out = StringIO.new
|
96
|
+
expect(Files.writer_like?(out)).to eq(true)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns true for a Tempfile' do
|
100
|
+
out = Tempfile.new('out')
|
101
|
+
begin
|
102
|
+
expect(Files.writer_like?(out)).to eq(true)
|
103
|
+
ensure
|
104
|
+
out.close
|
105
|
+
out.unlink
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'returns false for something that is not writer-like' do
|
110
|
+
expect(Files.writer_like?('not an IO')).to eq(false)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berkeley_library-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: berkeley_library-logging
|
@@ -260,6 +260,7 @@ files:
|
|
260
260
|
- berkeley_library-util.gemspec
|
261
261
|
- lib/berkeley_library/util.rb
|
262
262
|
- lib/berkeley_library/util/arrays.rb
|
263
|
+
- lib/berkeley_library/util/files.rb
|
263
264
|
- lib/berkeley_library/util/module_info.rb
|
264
265
|
- lib/berkeley_library/util/paths.rb
|
265
266
|
- lib/berkeley_library/util/stringios.rb
|
@@ -277,6 +278,7 @@ files:
|
|
277
278
|
- rakelib/spec.rake
|
278
279
|
- spec/.rubocop.yml
|
279
280
|
- spec/berkeley_library/util/arrays_spec.rb
|
281
|
+
- spec/berkeley_library/util/files_spec.rb
|
280
282
|
- spec/berkeley_library/util/paths_spec.rb
|
281
283
|
- spec/berkeley_library/util/stringios_spec.rb
|
282
284
|
- spec/berkeley_library/util/strings_spec.rb
|
@@ -311,6 +313,7 @@ summary: Miscellaneous Ruby utilities for the UC Berkeley Library
|
|
311
313
|
test_files:
|
312
314
|
- spec/.rubocop.yml
|
313
315
|
- spec/berkeley_library/util/arrays_spec.rb
|
316
|
+
- spec/berkeley_library/util/files_spec.rb
|
314
317
|
- spec/berkeley_library/util/paths_spec.rb
|
315
318
|
- spec/berkeley_library/util/stringios_spec.rb
|
316
319
|
- spec/berkeley_library/util/strings_spec.rb
|