Class: RIO::RL::URIBase
Constant Summary
collapse
- SCHEME =
URI::REGEXP::PATTERN::SCHEME
- HOST =
URI::REGEXP::PATTERN::HOST
Instance Attribute Summary collapse
Attributes inherited from Base
#fs
Instance Method Summary
collapse
Methods inherited from WithPath
#_build, #_parts, #_uri, #abs, #basename, #build_arg0_, #dirname, #filename, #fspath, #fspath=, #fspath_no_slash, #is_root?, #merge, #path_no_slash, #pathdepth, #route_from, #route_to, #split, #uri_from_string_
#nodef
Methods inherited from Base
#==, #===, #=~, #callstr, #close, #escape, #fs2url, #fspath, is_riorl?, #length, parse, #rl, split_riorl, subscheme, #to_rl, #unescape, #url2fs
Constructor Details
#initialize(u, *args) ⇒ URIBase
Returns a new instance of URIBase.
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/rio/rl/uri.rb', line 50
def initialize(u,*args)
@base = nil
@fs = nil
args = _get_opts_from_args(args)
init_from_args_(u,*args)
super
unless self.absolute? or @base
@base = ::URI::parse('file://'+RL.fs2url(fs.getwd)+'/')
end
@uri.path = '/' if @uri.absolute? and @uri.path == ''
end
|
Instance Attribute Details
Returns the value of attribute uri.
49
50
51
|
# File 'lib/rio/rl/uri.rb', line 49
def uri
@uri
end
|
Instance Method Details
#_get_base_from_arg(arg) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/rio/rl/uri.rb', line 91
def _get_base_from_arg(arg)
case arg
when RIO::Rio
arg.abs.to_uri
when URIBase
arg.abs.uri
when ::URI
arg if arg.absolute?
when ::String
uri_from_string_(arg) || ::URI.parse([RL.fs2url(::Dir.getwd+'/'),arg].join('/').squeeze('/'))
else
raise(ArgumentError,"'#{arg}' is not a valid base path")
end
end
|
#_get_opts_from_args(args) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/rio/rl/uri.rb', line 106
def _get_opts_from_args(args)
if !args.empty? and args[-1].kind_of?(::Hash)
opts = args.pop
if b = opts[:base]
@base = _get_base_from_arg(b)
end
if fs = opts[:fs]
@fs = fs
end
end
args
end
|
#absolute? ⇒ Boolean
Also known as:
abs?
124
125
126
|
# File 'lib/rio/rl/uri.rb', line 124
def absolute?()
uri.absolute?
end
|
#arg0_info_(arg0, *args) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rio/rl/uri.rb', line 63
def arg0_info_(arg0,*args)
vuri,vbase,vfs = nil,nil,nil
case arg0
when RIO::Rio
return _init_from_arg(arg0.rl)
when URIBase
vuri,vbase,vfs = arg0.uri,arg0.base,arg0.fs
when ::URI
vuri = arg0
when ::String
vuri = uri_from_string_(arg0) || ::URI.parse(arg0)
else
raise(ArgumentError,"'#{arg0}'[#{arg0.class}] can not be used to create a Rio")
end
[vuri,vbase,vfs]
end
|
182
183
184
|
# File 'lib/rio/rl/uri.rb', line 182
def base()
@base || self.uri
end
|
#base=(arg) ⇒ Object
185
186
187
188
|
# File 'lib/rio/rl/uri.rb', line 185
def base=(arg)
@base = _uri(arg)
end
|
156
|
# File 'lib/rio/rl/uri.rb', line 156
def host() uri.host end
|
#host=(arg) ⇒ Object
157
|
# File 'lib/rio/rl/uri.rb', line 157
def host=(arg) uri.host = arg end
|
#init_from_args_(arg0, *args) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/rio/rl/uri.rb', line 80
def init_from_args_(arg0,*args)
vuri,vbase,vfs = self.arg0_info_(arg0,*args)
@uri = vuri
self.join(*args)
@base = vbase unless @base or vbase.nil?
fs = vfs if vfs
end
|
#initialize_copy(*args) ⇒ Object
119
120
121
122
123
|
# File 'lib/rio/rl/uri.rb', line 119
def initialize_copy(*args)
super
@uri = @uri.clone unless @uri.nil?
@base = @base.clone unless @base.nil?
end
|
#join(*args) ⇒ Object
189
190
191
192
|
# File 'lib/rio/rl/uri.rb', line 189
def join(*args)
return self if args.empty?
join_(args.map{ |arg| arg.to_s})
end
|
158
159
160
161
162
|
# File 'lib/rio/rl/uri.rb', line 158
def opaque()
u = uri.clone
u.query = nil
u.to_s.sub(/^#{SCHEME}:/,'')
end
|
128
129
130
131
|
# File 'lib/rio/rl/uri.rb', line 128
def openfs_()
@fs || RIO::FS::Native.create()
end
|
143
144
145
146
147
148
|
# File 'lib/rio/rl/uri.rb', line 143
def path()
case scheme
when 'file','path' then fspath()
else urlpath()
end
end
|
#path=(pth) ⇒ Object
149
150
151
152
153
154
|
# File 'lib/rio/rl/uri.rb', line 149
def path=(pth)
case scheme
when 'file','path' then self.fspath = pth
else self.urlpath = pth
end
end
|
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/rio/rl/uri.rb', line 163
def pathroot()
u = uri.clone
u.query = nil
case scheme
when 'file'
if self.urlpath =~ %r%^(/[a-zA-Z]):% then $1+':/'
else '/'
end
else
u.path = '/'
u.to_s
end
end
|
155
|
# File 'lib/rio/rl/uri.rb', line 155
def scheme() uri.scheme end
|
135
136
137
|
# File 'lib/rio/rl/uri.rb', line 135
def to_s()
self.url
end
|
132
133
134
|
# File 'lib/rio/rl/uri.rb', line 132
def url()
self.uri.to_s
end
|
138
|
# File 'lib/rio/rl/uri.rb', line 138
def urlpath() uri.path end
|
#urlpath=(arg) ⇒ Object
139
140
141
142
|
# File 'lib/rio/rl/uri.rb', line 139
def urlpath=(arg)
uri.path = arg
end
|
176
177
178
179
180
181
|
# File 'lib/rio/rl/uri.rb', line 176
def urlroot()
return nil unless absolute?
cp = self.clone
cp.urlpath = self.pathroot
cp.url
end
|