berkeley_library-util 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab2d3fd2a0a839a3d733b0280ebff5b9b260b4cec4c2b06c6bdbe065d1b25871
4
- data.tar.gz: dcd700d56670c53e894e59239b9b90ab740d9761f7c80e67340428d357c290d1
3
+ metadata.gz: 8f8cd7e16b30baef3d05f38a78b698dfbc3a603b67f3573c8a2bbec9e2cac9b3
4
+ data.tar.gz: ebf19dd8fee5fe57a78942432d3f08e8bc486ac1ae69ba7a7ebad070ece90331
5
5
  SHA512:
6
- metadata.gz: 662ad15a9f80a79a379d70aa7fb4672b2f6e7adf3232796b6e814d238cb984ee8ebbc8e481d188d9fa92316929eb9e826a569eb5ccf6eb5892d96e6f0fa37d60
7
- data.tar.gz: 3bee84460660635c47f88102b0dc554ae0d5120089541d5733a45e785ab0ac8cfd56269beecf1d324b6174a594ab68b8133f4bc2a66db75d31d928c2c7390101
6
+ metadata.gz: 4ec9705be8f0b44019205a2bc72b5d24b982ddf463f88676e395de277cb6ff20687d3c4a5efc88de6f450a862e4351558dd9409bd35971970034c6b8e85ecea1
7
+ data.tar.gz: 0e77b5e7d5221ee6498ffba856d01ffa2faf216f3838bdd41db724e4207191cd97919bc1e24ba0ea5e483cc6ba83dea3672b258465ebe136bad1e5e3bd296b35
@@ -11,6 +11,10 @@
11
11
  <inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
12
12
  <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
13
13
  <inspection_tool class="RubyCaseWithoutElseBlockInspection" enabled="false" level="WARNING" enabled_by_default="false" />
14
+ <inspection_tool class="RubyMismatchedReturnType" enabled="true" level="WARNING" enabled_by_default="true">
15
+ <option name="myCheckNilability" value="false" />
16
+ </inspection_tool>
17
+ <inspection_tool class="RubyNilAnalysis" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
14
18
  <inspection_tool class="RubyStringKeysInHashInspection" enabled="true" level="INFORMATION" enabled_by_default="true" />
15
19
  <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
16
20
  <option name="processCode" value="true" />
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.1.1 (2021-09-23)
2
+
3
+ - `URIs.append` now handles bare URLs with empty paths, with the caveat that
4
+ a root path `/` will always be added, even if there are no path elements to append.
5
+
1
6
  # 0.1.0 (2021-09-23)
2
7
 
3
- Initial extraction of code from [`berkeley_library/tind`](https://github.com/BerkeleyLibrary/tind).
8
+ - Initial extraction of code from [`berkeley_library/tind`](https://github.com/BerkeleyLibrary/tind).
data/README.md CHANGED
@@ -7,15 +7,15 @@ Miscellaneous utility code for the UC Berkeley Library.
7
7
 
8
8
  ### Notable modules
9
9
 
10
- ## [BerkeleyLibrary::Util::Arrays](lib/berkeley_library/util/arrays.rb)]
10
+ ## [BerkeleyLibrary::Util::Arrays](lib/berkeley_library/util/arrays.rb)
11
11
 
12
12
  Routines for comparing, merging, and examining the contents of arrays.
13
13
 
14
- ## [BerkeleyLibrary::Util::Paths](lib/berkeley_library/util/paths.rb)]
14
+ ## [BerkeleyLibrary::Util::Paths](lib/berkeley_library/util/paths.rb)
15
15
 
16
16
  Routines for modifying paths separated by forward slashes,
17
17
  (such as URL paths), modeled on the [Go `path` package](https://golang.org/pkg/path/).
18
18
 
19
- ## [BerkeleyLibrary::Util::URIs](lib/berkeley_library/util/uris.rb)]
19
+ ## [BerkeleyLibrary::Util::URIs](lib/berkeley_library/util/uris.rb)
20
20
 
21
21
  Routines for constructing, validating, and retrieving the content from URIs.
@@ -9,7 +9,7 @@ module BerkeleyLibrary
9
9
  A collection of miscellaneous Ruby routines for the UC Berkeley Library.
10
10
  DESC
11
11
  LICENSE = 'MIT'.freeze
12
- VERSION = '0.1.0'.freeze
12
+ VERSION = '0.1.1'.freeze
13
13
  HOMEPAGE = 'https://github.com/BerkeleyLibrary/util'.freeze
14
14
  end
15
15
  end
@@ -55,6 +55,14 @@ module BerkeleyLibrary
55
55
  clean(joined_raw)
56
56
  end
57
57
 
58
+ def abs?(path)
59
+ path.to_s.start_with?('/')
60
+ end
61
+
62
+ def ensure_abs(path)
63
+ abs?(path) ? path : "/#{path}"
64
+ end
65
+
58
66
  private
59
67
 
60
68
  def process_next(r, dotdot, path, out)
@@ -35,7 +35,8 @@ module BerkeleyLibrary
35
35
  # @raise URI::InvalidComponentError if appending the specified elements would create an invalid URI
36
36
  def to_uri
37
37
  original_uri.dup.tap do |new_uri|
38
- new_uri.path = Paths.join(original_uri.path, *path_elements)
38
+ new_path = Paths.join(new_uri.path, *path_elements)
39
+ new_uri.path = Paths.ensure_abs(new_path)
39
40
  new_uri.query = query unless query_elements.empty?
40
41
  new_uri.fragment = fragment unless fragment_elements.empty?
41
42
  end
@@ -30,6 +30,8 @@ module BerkeleyLibrary
30
30
 
31
31
  elements = [].tap do |ee|
32
32
  ee << url_str
33
+ next if params.empty?
34
+
33
35
  ee << '?' unless url_str.include?('?')
34
36
  ee << URI.encode_www_form(params)
35
37
  end
@@ -44,18 +44,15 @@ module BerkeleyLibrary
44
44
  expect(result).to eq(expected_body)
45
45
  end
46
46
 
47
- it 'raises an error for a failure status' do
48
- url = 'https://example.org/'
49
- stub_request(:get, url).to_return(status: 404)
50
-
51
- expect { Requester.get(url) }.to raise_error(RestClient::RequestFailed)
52
- end
53
-
54
- it 'raises an error for a weird non-failure status' do
55
- url = 'https://example.org/'
56
- stub_request(:get, url).to_return(status: 207)
47
+ it "raises #{RestClient::Exception} in the event of an invalid response" do
48
+ aggregate_failures 'responses' do
49
+ [207, 400, 401, 403, 404, 405, 418, 451, 500, 503].each do |code|
50
+ url = "http://example.edu/#{code}"
51
+ stub_request(:get, url).to_return(status: code)
57
52
 
58
- expect { Requester.get(url) }.to raise_error(RestClient::RequestFailed)
53
+ expect { Requester.get(url) }.to raise_error(RestClient::Exception)
54
+ end
55
+ end
59
56
  end
60
57
 
61
58
  it 'handles redirects' do
@@ -9,6 +9,29 @@ module BerkeleyLibrary::Util
9
9
  expect(new_uri).to eq(URI('https://example.org/foo/bar/qux/corge/garply'))
10
10
  end
11
11
 
12
+ it 'appends paths to bare URIs without root' do
13
+ original_url = 'https://example.org'
14
+ new_uri = URIs.append(original_url, 'foo', 'bar')
15
+ expected_uri = URI('https://example.org/foo/bar')
16
+ expect(new_uri).to eq(expected_uri)
17
+ end
18
+
19
+ # TODO: make this work
20
+ xit "doesn't append to a bare URI when there's nothing to append" do
21
+ original_url = 'https://example.org'
22
+ new_uri = URIs.append(original_url)
23
+ expected_uri = URI(original_url)
24
+ expect(new_uri).to eq(expected_uri)
25
+ end
26
+
27
+ # TODO: make this work
28
+ xit "doesn't append to a bare URI when there's only a query string" do
29
+ original_url = 'https://example.org'
30
+ new_uri = URIs.append(original_url, '?foo=bar')
31
+ expected_uri = URI("#{original_url}?foo=bar")
32
+ expect(new_uri).to eq(expected_uri)
33
+ end
34
+
12
35
  it 'does not modify the original URI' do
13
36
  original_uri = URI('https://example.org/foo/bar')
14
37
  original_url = original_uri.to_s
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-23 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: berkeley_library-logging