Class: Diva::URI
- Inherits:
-
Object
show all
- Defined in:
- lib/diva/uri.rb
Instance Method Summary
collapse
Constructor Details
#initialize(uri) ⇒ URI
Returns a new instance of URI.
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/diva/uri.rb', line 34
def initialize(uri)
@uri = @uri_string = @uri_hash = nil
case uri.freeze
when URI, Addressable::URI
@uri = uri
when String
@uri_string = uri
when Hash
@uri_hash = uri
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *rest, &block) ⇒ Object
108
109
110
|
# File 'lib/diva/uri.rb', line 108
def method_missing(method, *rest, &block)
to_uri.__send__(method, *rest, &block)
end
|
Instance Method Details
#==(other) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/diva/uri.rb', line 46
def ==(other)
case other
when URI, Addressable::URI, String
other.to_s == to_s
when Diva::URI
if has_string? || other.has_string?
to_s == other.to_s
else
other.to_uri == to_uri
end
end
end
|
#eql?(other) ⇒ Boolean
63
64
65
|
# File 'lib/diva/uri.rb', line 63
def eql?(other)
self == other
end
|
#freeze ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/diva/uri.rb', line 96
def freeze
unless frozen?
to_uri
to_s
end
super
end
|
#has_string? ⇒ Boolean
67
68
69
|
# File 'lib/diva/uri.rb', line 67
def has_string?
!!@uri_string
end
|
#has_uri? ⇒ Boolean
71
72
73
|
# File 'lib/diva/uri.rb', line 71
def has_uri?
!!@uri
end
|
#hash ⇒ Object
59
60
61
|
# File 'lib/diva/uri.rb', line 59
def hash
to_s.hash ^ self.class.hash
end
|
#respond_to_missing?(method, include_private) ⇒ Boolean
104
105
106
|
# File 'lib/diva/uri.rb', line 104
def respond_to_missing?(method, include_private)
to_uri.respond_to?(method, include_private)
end
|
#scheme ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/diva/uri.rb', line 83
def scheme
if has_string? && !has_uri?
match = @uri_string.match(%r<\A(\w+):>)
if match
match[1]
else
to_uri.scheme
end
else
to_uri.scheme
end
end
|
#to_s ⇒ Object
75
76
77
|
# File 'lib/diva/uri.rb', line 75
def to_s
@uri_string ||= to_uri.to_s.freeze end
|
#to_uri ⇒ Object
79
80
81
|
# File 'lib/diva/uri.rb', line 79
def to_uri
@uri ||= generate_uri.freeze end
|