librariesio-url-parser 1.0.5 → 1.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7678a02447f9ecb298aca33105ed4a0a686258b39e1dbbf6069cadcc8bb5ee9
4
- data.tar.gz: f5c7d4fa5dca4858e46f7740b33f4e54f67230e2801a2e2cfb00bfae7f1aad6a
3
+ metadata.gz: bae64bd33bdd5556d8d16472bf9c815813375f60254335b0e39c8e80a669249f
4
+ data.tar.gz: 06b4b0e89906bcf89d8679e96c48028991a0f77eeb200950b617c02a2b8671ba
5
5
  SHA512:
6
- metadata.gz: 940d8eccc878fe614347f7e18f381825f531cf2f14a0f22834bbd342e8ebf6be13e4daeb5c07e2627446ba5d5df76af8b634285731479ce6fe4d38807fb29326
7
- data.tar.gz: 928daf9d94eeed789e059e099dd6346e7c6d1b4cbaee1f788d8d36dc2420fdd232c74a7ed68f051aa91efa26d1d6636107d89deee06e082d0fd7c2f6398b90ca
6
+ metadata.gz: 19ab606c3ee731d48df907595b9a6ccaf01ded2dd4606928744766f729ea1718d776a1be481f12c9cae34f2e0b4b2109fc12ce895cc016b499c2767661c94cf0
7
+ data.tar.gz: 3aab091fb8161ea1d928cfd51eddbfc66b9b8a6d8f1c446e247f1c3417a5908a27a07d14057656835a73d98d6e276ad08da1467f2dd394f6a1c5fbe2e6fd991d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- librariesio-url-parser (1.0.5)
4
+ librariesio-url-parser (1.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  class AndroidGooglesourceUrlParser < URLParser
3
+ CASE_SENSITIVE = true
4
+
3
5
  private
4
6
 
5
7
  def full_domain
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  class ApacheGitWipUrlParser < URLParser
3
+ CASE_SENSITIVE = true
4
+
3
5
  private
4
6
 
5
7
  def full_domain
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  class ApacheGitboxUrlParser < URLParser
3
+ CASE_SENSITIVE = true
4
+
3
5
  private
4
6
 
5
7
  def full_domain
@@ -2,6 +2,8 @@
2
2
  class ApacheSvnUrlParser < URLParser
3
3
  SUBDIR_NAMES = %w[trunk tags branches].freeze
4
4
  VALID_PATHS = %w[viewvc viewcvs\.cgi repos\/asf].freeze
5
+ CASE_SENSITIVE = true
6
+
5
7
  private
6
8
 
7
9
  def full_domain
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  class EclipseGitUrlParser < URLParser
3
+ CASE_SENSITIVE = true
4
+
3
5
  private
4
6
 
5
7
  def full_domain
@@ -13,5 +13,5 @@ require_relative "android_googlesource_url_parser"
13
13
  require_relative "sourceforge_url_parser"
14
14
 
15
15
  module LibrariesioURLParser
16
- VERSION = "1.0.5"
16
+ VERSION = "1.0.7"
17
17
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  class SourceforgeUrlParser < URLParser
3
3
  PROJECT_PATHS = %w[projects p].freeze
4
+
4
5
  private
5
6
 
6
7
  def full_domain
data/lib/url_parser.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class URLParser
4
+ CASE_SENSITIVE = false
5
+
4
6
  def self.parse(url)
5
7
  new(url).parse
6
8
  end
@@ -31,7 +33,7 @@ class URLParser
31
33
  def self.try_all(url)
32
34
  # run through all the subclasses and try their parse method
33
35
  # exit the reduce at the first non nil value and return that
34
- descendants.reduce(nil) do |_, n|
36
+ all_parsers.reduce(nil) do |_, n|
35
37
  r = n.parse_to_full_url(url)
36
38
  break r if r
37
39
  end
@@ -53,6 +55,27 @@ class URLParser
53
55
  [full_domain, path].join('/')
54
56
  end
55
57
 
58
+ def self.case_sensitive?
59
+ self::CASE_SENSITIVE
60
+ end
61
+
62
+ # This computation is memoized because it is expensive. This prevents use cases which require using
63
+ # .try_all in a tight loop. However, if this class is required directly (without requiring any subparsers),
64
+ # this method will memoize an empty array. It is recommended to simply require librariesio-url-parser.rb directly.
65
+ # This is the default behavior when installing this gem.
66
+ def self.all_parsers
67
+ @all_parsers ||=
68
+ begin
69
+ all_parsers = []
70
+ ObjectSpace.each_object(singleton_class) do |k|
71
+ next if k.singleton_class?
72
+
73
+ all_parsers.unshift k unless k == self
74
+ end
75
+ all_parsers
76
+ end
77
+ end
78
+
56
79
  private
57
80
 
58
81
  attr_accessor :url
@@ -73,9 +96,9 @@ class URLParser
73
96
 
74
97
  remove_subdomain
75
98
  remove_domain
76
- remove_git_extension
77
99
  remove_git_scheme
78
100
  remove_extra_segments
101
+ remove_git_extension
79
102
  end
80
103
 
81
104
  def format_url
@@ -145,7 +168,7 @@ class URLParser
145
168
  end
146
169
 
147
170
  def remove_git_extension
148
- url.gsub!(/(\.git|\/)$/i, '')
171
+ Array(url).last&.gsub!(/(\.git|\/)$/i, '')
149
172
  end
150
173
 
151
174
  def remove_git_scheme
@@ -167,21 +190,4 @@ class URLParser
167
190
  def remove_whitespace
168
191
  url.gsub!(/\s/, '')
169
192
  end
170
-
171
- # This computation is memoized because it is expensive. This prevents use cases which require using
172
- # .try_all in a tight loop. However, if this class is required directly (without requiring any subparsers),
173
- # this method will memoize an empty array. It is recommended to simply require librariesio-url-parser.rb directly.
174
- # This is the default behavior when installing this gem.
175
- private_class_method def self.descendants
176
- @descendants ||=
177
- begin
178
- descendants = []
179
- ObjectSpace.each_object(singleton_class) do |k|
180
- next if k.singleton_class?
181
-
182
- descendants.unshift k unless k == self
183
- end
184
- descendants
185
- end
186
- end
187
193
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librariesio-url-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Pace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-22 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake