addressabler 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
+ ## 0.0.6
2
+ * Merged [pull request from Jean Mertz][1] adding custom TLD support
3
+
1
4
  ## 0.0.5
2
5
  * Restored nested hash support **if Rack is installed**
3
6
 
4
7
  ## 0.0.4
5
8
  * Updated to the latest TLD list from [Paul Dix](https://github.com/pauldix), thanks to [this unbelievably helpful user](https://github.com/flipsasser/addressabler/issues/1)
6
9
  * Updated to latest Addressable spec
10
+
11
+ [1](https://github.com/flipsasser/addressabler/pull/2)
data/README.md CHANGED
@@ -1,17 +1,20 @@
1
1
  # Addressabler
2
2
 
3
- **Addressabler** extends the [Addressable::URI](https://github.com/sporkmonger/addressable) class by adding TLD parsing, domain and subdomain parsing, query modification, and restoring setting of nested hashes to query strings.
3
+ **Addressabler** extends the
4
+ [Addressable::URI](https://github.com/sporkmonger/addressable) class by adding
5
+ TLD parsing, domain and subdomain parsing, query modification, and restoring
6
+ setting of nested hashes to query strings.
4
7
 
5
8
  ## Install
6
9
 
7
10
  Install using Rubygems:
8
11
 
9
- gem install addressabler
12
+ gem install addressabler
10
13
 
11
14
  Then:
12
15
 
13
- require 'rubygems'
14
- require 'addressabler'
16
+ require 'rubygems'
17
+ require 'addressabler'
15
18
 
16
19
  Addressabler will automatically require `addressable/uri`.
17
20
 
@@ -21,14 +24,14 @@ Addressabler will automatically require `addressable/uri`.
21
24
 
22
25
  Use `Addressable::URI` like you normally would:
23
26
 
24
- ```
27
+ ```ruby
25
28
  @uri = Addressable::URI.parse("http://www.google.com/")
26
29
  @uri.host #=> "www.google.com"
27
30
  ```
28
31
 
29
32
  Addressabler will add the following properties:
30
33
 
31
- ```
34
+ ```ruby
32
35
  @uri.tld #=> "com"
33
36
  @uri.domain #=> "google"
34
37
  @uri.subdomain #=> "www"
@@ -36,7 +39,7 @@ Addressabler will add the following properties:
36
39
 
37
40
  You can set these values, as well:
38
41
 
39
- ```
42
+ ```ruby
40
43
  @uri.tld = "org"
41
44
  @uri.host #=> "www.google.org"
42
45
  @uri.domain = "amazon"
@@ -46,37 +49,61 @@ You can set these values, as well:
46
49
  ```
47
50
 
48
51
  #### Complex TLD support (thanks to Paul Dix!)
49
- Addressabler copies some of Paul Dix's [Domaintrix](https://github.com/pauldix/domainatrix) TLD code to support fancy TLDs, as well:
52
+ Addressabler copies some of Paul Dix's
53
+ [Domaintrix](https://github.com/pauldix/domainatrix) TLD code to support fancy
54
+ TLDs, as well:
50
55
 
51
- ```
56
+ ```ruby
52
57
  @uri.host = "www.google.co.uk"
53
58
  @uri.tld #=> "co.uk"
54
59
  ```
55
60
 
61
+ #### Custom TLDs
62
+ You can specify custom TLDs - which aren't actually working TLD's on the
63
+ internet - for internal usage. One example would be a custom development TLD:
64
+
65
+ ```ruby
66
+ Addressable::URI.custom_tlds = {
67
+ 'dev' => {}, # mydomain.dev
68
+ 'bar' => { 'foo' => {} } # mydomain.foo.bar
69
+ }
70
+ ```
71
+
56
72
  ### Query interface
57
73
 
58
- Addressabler adds a `query_hash` method to `Addressable::URI`s. This makes editing query strings a lot simpler, using a familiar Hash syntax:
74
+ Addressabler adds a `query_hash` method to `Addressable::URI`s. This makes
75
+ editing query strings a lot simpler, using a familiar Hash syntax:
59
76
 
60
- ```
77
+ ```ruby
61
78
  @uri.query_hash[:foo] = :bar
62
79
  @uri.to_s #=> "http://www.google.co.uk/?foo=bar"
63
80
  ```
64
81
 
65
82
  #### Nested hashes in query strings
66
83
 
67
- The current maintainer of Addressable, [Bob Aman](https://github.com/sporkmonger), feels rather strongly that [Rails got it wrong](https://github.com/sporkmonger/addressable/issues/77) in supporting nested hashes in query strings.
84
+ The current maintainer of Addressable, [Bob
85
+ Aman](https://github.com/sporkmonger), feels rather strongly that [Rails got it
86
+ wrong](https://github.com/sporkmonger/addressable/issues/77) in supporting
87
+ nested hashes in query strings.
68
88
 
69
- Frankly, I don't disagree with anything he has to say on the issue, but it is a problem many people have experienced.
89
+ Frankly, I don't disagree with anything he has to say on the issue, but it is a
90
+ problem many people have experienced.
70
91
 
71
- *As such,* since Rack already supports building nested hashes "the Rails Way" (shudder), I added support for assigning nested hashes to `URI`s **only if Rack is available.** Addressabler will attempt to load `Rack::Utils` and, if it finds it, you can assign a nested hash in the `query_hash=` method like so:
92
+ *As such,* since Rack already supports building nested hashes "the Rails Way"
93
+ (shudder), I added support for assigning nested hashes to `URI`s **only if Rack
94
+ is available.** Addressabler will attempt to load `Rack::Utils` and, if it finds
95
+ it, you can assign a nested hash in the `query_hash=` method like so:
72
96
 
73
- ```
97
+ ```ruby
74
98
  @uri.query_hash = {:foo => {:bar => :baz}}
75
99
  @uri.to_s #=> "http://www.google.co.uk/?foo[bar]=baz"
76
100
  ```
77
101
 
78
- **HANDLE WITH CARE!** As [Bob explains in the discussion](https://github.com/sporkmonger/addressable/issues/77#issuecomment-8534480), there's a better alternative to nested hashes in query strings, so try that before you install this library.
102
+ **HANDLE WITH CARE!** As [Bob explains in the discussion]
103
+ (https://github.com/sporkmonger/addressable/issues/77#issuecomment-8534480),
104
+ there's a better alternative to nested hashes in query strings, so try that
105
+ before you install this library.
79
106
 
80
107
  That's it. Enjoy.
81
108
 
82
- #### Copyright © 2013 Flip Sasser
109
+ #### Copyright © 2013 Flip Sasser
data/lib/addressabler.rb CHANGED
@@ -2,12 +2,19 @@ require 'rubygems'
2
2
  require 'addressable/uri'
3
3
  require 'addressabler/query'
4
4
 
5
+ module Addressable
6
+ class URI
7
+ class << self; attr_accessor :custom_tlds; end
8
+ @custom_tlds = {}
9
+ end
10
+ end
11
+
5
12
  module Addressabler
6
13
  module ClassMethods
7
14
  def parse_tld(host)
8
15
  host = host.to_s.split('.')
9
16
  tlds = []
10
- sub_hash = Addressabler::TLDS
17
+ sub_hash = Addressabler::TLDS.merge(@custom_tlds)
11
18
  while sub_hash = sub_hash[tld = host.pop]
12
19
  tlds.unshift(tld)
13
20
  if sub_hash.has_key? '*'
@@ -26,6 +26,23 @@ describe Addressabler do
26
26
  uri = Addressable::URI.parse("http://www.bart-blabla.cc")
27
27
  uri.tld.should == 'cc'
28
28
  end
29
+
30
+ it "doesn't know non-existing TLDs" do
31
+ uri = Addressable::URI.parse("http://www.bart-blabla.foobar")
32
+ uri.tld.should == ''
33
+ end
34
+
35
+ it "accepts custom TLDs" do
36
+ Addressable::URI.custom_tlds = { 'foobar' => {} }
37
+ uri = Addressable::URI.parse("http://www.bart-blabla.foobar")
38
+ uri.tld.should == 'foobar'
39
+ end
40
+
41
+ it "accepts nested custom TLDs" do
42
+ Addressable::URI.custom_tlds = { 'bar' => { 'foo' => {} } }
43
+ uri = Addressable::URI.parse("http://www.bart-blabla.foo.bar")
44
+ uri.tld.should == 'foo.bar'
45
+ end
29
46
  end
30
47
 
31
48
  it "should support adding keys to the query" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressabler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-25 00:00:00.000000000 Z
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -91,6 +91,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ segments:
95
+ - 0
96
+ hash: 2089410435021275107
94
97
  required_rubygems_version: !ruby/object:Gem::Requirement
95
98
  none: false
96
99
  requirements: