adomain 0.1.2 → 0.2.4
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.lock +15 -15
- data/README.md +55 -20
- data/adomain.gemspec +1 -1
- data/lib/adomain.rb +32 -11
- data/lib/adomain/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07e8678866573d16ab4fc9fe09ed4ac489ee494d7135cc66fd60ddf14141ae80
|
4
|
+
data.tar.gz: 94e364cc3d2fa19e59291ae1cc2b6483754817d2b8af39afd5881ad06d648ecc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afab2fa4bbaea7a7c4528d4bf5a92035cd92ba4739d4bc4a39e519f6ad549e8d17d4d8ac912c8a17460db8d50a9ab75b318ae2fb0299b022d808beb5f2c208f9
|
7
|
+
data.tar.gz: 5ee96ec92e589778e02969a22dff12ac98439024af534196daee14a37bf8a2a7580e2e590514436dc35848e92dd1e18d1c88665e2f90bb1ed7c1447651f58779
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
adomain (0.
|
4
|
+
adomain (0.2.3)
|
5
5
|
addressable (~> 2.5)
|
6
6
|
logger
|
7
7
|
|
@@ -13,20 +13,20 @@ GEM
|
|
13
13
|
diff-lcs (1.3)
|
14
14
|
logger (1.4.1)
|
15
15
|
public_suffix (4.0.1)
|
16
|
-
rake (
|
17
|
-
rspec (3.
|
18
|
-
rspec-core (~> 3.
|
19
|
-
rspec-expectations (~> 3.
|
20
|
-
rspec-mocks (~> 3.
|
21
|
-
rspec-core (3.
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-expectations (3.
|
16
|
+
rake (13.0.1)
|
17
|
+
rspec (3.9.0)
|
18
|
+
rspec-core (~> 3.9.0)
|
19
|
+
rspec-expectations (~> 3.9.0)
|
20
|
+
rspec-mocks (~> 3.9.0)
|
21
|
+
rspec-core (3.9.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-expectations (3.9.0)
|
24
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-mocks (3.
|
25
|
+
rspec-support (~> 3.9.0)
|
26
|
+
rspec-mocks (3.9.0)
|
27
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-support (3.
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-support (3.9.0)
|
30
30
|
|
31
31
|
PLATFORMS
|
32
32
|
ruby
|
@@ -34,8 +34,8 @@ PLATFORMS
|
|
34
34
|
DEPENDENCIES
|
35
35
|
adomain!
|
36
36
|
bundler (~> 1.16)
|
37
|
-
rake (~>
|
37
|
+
rake (~> 13.0)
|
38
38
|
rspec (~> 3.0)
|
39
39
|
|
40
40
|
BUNDLED WITH
|
41
|
-
1.
|
41
|
+
1.17.3
|
data/README.md
CHANGED
@@ -13,10 +13,12 @@ Adomain["https://www.xyz.com"]
|
|
13
13
|
# => "xyz.com"
|
14
14
|
```
|
15
15
|
|
16
|
-
Adomain returns the URL host, stripping 'www' by default,
|
17
|
-
|
16
|
+
Adomain returns the URL host, stripping 'www' by default,
|
17
|
+
scheming your URL if necessary (with "https://").
|
18
|
+
Optionally, you can strip subdomains or keep 'www' subdomains – see below.
|
18
19
|
|
19
|
-
[`Addressable::URI.parse`](https://github.com/sporkmonger/addressable#example-usage)
|
20
|
+
[`Addressable::URI.parse`](https://github.com/sporkmonger/addressable#example-usage)
|
21
|
+
performs the parsing.
|
20
22
|
|
21
23
|
## Other methods and options
|
22
24
|
|
@@ -41,36 +43,62 @@ Adomain.domain "http://abc.xyz.com" # => "xyz.com"
|
|
41
43
|
Adomain.subdomain_www "http://www.xyz.com" # => "www.xyz.com"
|
42
44
|
```
|
43
45
|
|
46
|
+
### Domain options
|
47
|
+
|
44
48
|
Optionally, each method accepts boolean values,
|
45
49
|
allowing you to contort the method to do something other
|
46
50
|
than what it says it does. Don't do this, unless you want to.
|
47
51
|
|
48
|
-
|
52
|
+
#### A gotcha: Adomain returns nil for some invalid values
|
49
53
|
|
50
|
-
Because Adomain adds a scheme to any string passed to it
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
Because Adomain adds a scheme to any string passed to it,
|
55
|
+
schemeless-but-otherwise valid strings do not raise errors.
|
56
|
+
Additionally, Adomain rescues InvalidURIError errors,
|
57
|
+
and instead returns nil.
|
54
58
|
|
55
59
|
```ruby
|
56
60
|
Adomain["hola"] # => nil
|
57
61
|
Adomain["::::::::"] # => nil
|
58
|
-
Adomain[""] # =>
|
59
|
-
Adomain["{}"] # =>
|
60
|
-
Gem::Version.new(Adomain::VERSION) >= Gem::Version.new(0.2) # => false
|
62
|
+
Adomain[""] # => nil
|
63
|
+
Adomain["{}"] # => nil
|
61
64
|
```
|
62
65
|
|
63
|
-
####
|
66
|
+
#### NOTE: InvalidURIError are now caught in >= version 0.2
|
64
67
|
|
65
|
-
|
66
|
-
and ignored. Nil
|
68
|
+
With 0.2 `Addressable::URI::InvalidURIError`s are now caught
|
69
|
+
and ignored. Nil is returned.
|
67
70
|
|
68
71
|
```ruby
|
69
72
|
Gem::Version.new(Adomain::VERSION) >= Gem::Version.new(0.2) # => true
|
70
73
|
Adomain["hola"] # => nil
|
71
74
|
Adomain["::::::::"] # => nil
|
72
|
-
Adomain[""] # => nil
|
73
|
-
Adomain["{}"] # => nil
|
75
|
+
Adomain[""] # => nil (formerly raised a Addressable::URI::InvalidURIError)
|
76
|
+
Adomain["{}"] # => nil (formerly raised a Addressable::URI::InvalidURIError)
|
77
|
+
```
|
78
|
+
|
79
|
+
### Convenience Addressable passthroughs
|
80
|
+
|
81
|
+
These methods are simply passed through to parsed
|
82
|
+
Addressable URI objects, and respond accordingly.
|
83
|
+
These are presented for your convenience, and will track with
|
84
|
+
your version of Addressable.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
Adomain.path "http://www.xyz.com/pages/123" # => "/pages/123"
|
88
|
+
Adomain.path "{{{{{" # => "{{{{{"
|
89
|
+
Adomain.scheme "http://www.xyz.com/pages/123" # => "http"
|
90
|
+
Adomain.scheme "harrison:ford" # => "harrison"
|
91
|
+
Adomain.query_values "https://maximumfun.org/donate?amt=20USD" # => {"amt"=>"20USD"}
|
92
|
+
Adomain.query_values "google.com?q=gagh.biz" # => {"q"=>"gagh.biz"}
|
93
|
+
```
|
94
|
+
|
95
|
+
However, they are rescued from InvalidURIError,
|
96
|
+
like in other parts of the gem.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
Adomain.path "::::::::::::" #=> nil
|
100
|
+
Adomain.scheme "::::::::::::" #=> nil
|
101
|
+
Adomain.query_values "::::::::::::" #=> nil
|
74
102
|
```
|
75
103
|
|
76
104
|
## Installation
|
@@ -89,16 +117,23 @@ Or install it yourself as:
|
|
89
117
|
|
90
118
|
## Development
|
91
119
|
|
92
|
-
File bugs against the GitHub issue tracker and pull requests to match,
|
120
|
+
File bugs against the GitHub issue tracker and pull requests to match,
|
121
|
+
where possible.
|
93
122
|
|
94
123
|
## Contributing
|
95
124
|
|
96
|
-
Bug reports and pull requests are welcome on GitHub at
|
125
|
+
Bug reports and pull requests are welcome on GitHub at
|
126
|
+
https://github.com/samnissen/adomain. This project is intended to be a safe,
|
127
|
+
welcoming space for collaboration, and contributors are expected to adhere
|
128
|
+
to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
97
129
|
|
98
130
|
## License
|
99
131
|
|
100
|
-
The gem is available as open source under the terms of the
|
132
|
+
The gem is available as open source under the terms of the
|
133
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
101
134
|
|
102
135
|
## Code of Conduct
|
103
136
|
|
104
|
-
Everyone interacting in the Adomain project’s codebases, issue trackers,
|
137
|
+
Everyone interacting in the Adomain project’s codebases, issue trackers,
|
138
|
+
chat rooms and mailing lists is expected to follow the
|
139
|
+
[code of conduct](https://github.com/samnissen/adomain/blob/master/CODE_OF_CONDUCT.md).
|
data/adomain.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
-
spec.add_development_dependency "rake", "~>
|
24
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
26
|
|
27
27
|
spec.add_dependency "addressable", "~> 2.5"
|
data/lib/adomain.rb
CHANGED
@@ -4,14 +4,6 @@ require "logger"
|
|
4
4
|
|
5
5
|
class Adomain
|
6
6
|
class << self
|
7
|
-
|
8
|
-
ADDRESSABLE_WARNING = %{
|
9
|
-
WARNING: breaking change planned:
|
10
|
-
Adomain will catch Addressable::URI::InvalidURIError.
|
11
|
-
This error will be caught in version 0.2.
|
12
|
-
Any code relying on the error will break.
|
13
|
-
}.gsub(/\s+/, ' ').strip
|
14
|
-
|
15
7
|
# [] is a convenience method to subdomain the URL,
|
16
8
|
# or optionally domain or subdomain_www.
|
17
9
|
# Adomain["http://abc.xyz.com"] # => "abc.xyz.com"
|
@@ -49,6 +41,37 @@ class Adomain
|
|
49
41
|
subdomain(string, true)
|
50
42
|
end
|
51
43
|
|
44
|
+
# scheme is a wrapper around Addressable::URI's scheme
|
45
|
+
# it is only included for convenience
|
46
|
+
def scheme(string)
|
47
|
+
Addressable::URI.parse(string).scheme
|
48
|
+
rescue Addressable::URI::InvalidURIError => e
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
52
|
+
# path is a wrapper around Addressable::URI's path
|
53
|
+
# with a major difference -- it removes the domain components
|
54
|
+
# from the string, if the domain is parseable. This is because
|
55
|
+
# Addressable leaves it in, for reasons I can't understand.
|
56
|
+
def path(string)
|
57
|
+
if self.subdomain_www(string)
|
58
|
+
substring = /\A#{Regexp.quote(self.subdomain_www(string))}/
|
59
|
+
Addressable::URI.parse(string).path.gsub(substring, '')
|
60
|
+
else
|
61
|
+
Addressable::URI.parse(string).path
|
62
|
+
end
|
63
|
+
rescue Addressable::URI::InvalidURIError => e
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
# query_values is a wrapper around Addressable::URI's query_values
|
68
|
+
# it is only included for convenience
|
69
|
+
def query_values(string)
|
70
|
+
Addressable::URI.parse(string).query_values
|
71
|
+
rescue Addressable::URI::InvalidURIError => e
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
|
52
75
|
private
|
53
76
|
# parse_for_domain accepts one hash of arguments that allow
|
54
77
|
# changes to the parsing behavior of domains
|
@@ -85,9 +108,7 @@ class Adomain
|
|
85
108
|
|
86
109
|
return domain
|
87
110
|
rescue Addressable::URI::InvalidURIError => e
|
88
|
-
|
89
|
-
|
90
|
-
raise e
|
111
|
+
nil
|
91
112
|
end
|
92
113
|
|
93
114
|
def logger
|
data/lib/adomain/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adomain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Nissen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.7.10
|
123
|
+
rubygems_version: 3.1.2
|
125
124
|
signing_key:
|
126
125
|
specification_version: 4
|
127
126
|
summary: Simple, uncomplicated, schemed domain parsing using Addressable
|