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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/rio/rl/uri.rb', line 95
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
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/rio/rl/uri.rb', line 110
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?
128
129
130
|
# File 'lib/rio/rl/uri.rb', line 128
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
80
|
# 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
|
186
187
188
|
# File 'lib/rio/rl/uri.rb', line 186
def base()
@base || self.uri
end
|
#base=(arg) ⇒ Object
189
190
191
192
|
# File 'lib/rio/rl/uri.rb', line 189
def base=(arg)
@base = _uri(arg)
end
|
160
|
# File 'lib/rio/rl/uri.rb', line 160
def host() uri.host end
|
#host=(arg) ⇒ Object
161
|
# File 'lib/rio/rl/uri.rb', line 161
def host=(arg) uri.host = arg end
|
#init_from_args_(arg0, *args) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/rio/rl/uri.rb', line 81
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
123
124
125
126
127
|
# File 'lib/rio/rl/uri.rb', line 123
def initialize_copy(*args)
super
@uri = @uri.clone unless @uri.nil?
@base = @base.clone unless @base.nil?
end
|
#join(*args) ⇒ Object
193
194
195
196
|
# File 'lib/rio/rl/uri.rb', line 193
def join(*args)
return self if args.empty?
join_(args.map{ |arg| arg.to_s})
end
|
162
163
164
165
166
|
# File 'lib/rio/rl/uri.rb', line 162
def opaque()
u = uri.clone
u.query = nil
u.to_s.sub(/^#{SCHEME}:/,'')
end
|
132
133
134
135
|
# File 'lib/rio/rl/uri.rb', line 132
def openfs_()
@fs || RIO::FS::Native.create()
end
|
147
148
149
150
151
152
|
# File 'lib/rio/rl/uri.rb', line 147
def path()
case scheme
when 'file','path' then fspath()
else urlpath()
end
end
|
#path=(pth) ⇒ Object
153
154
155
156
157
158
|
# File 'lib/rio/rl/uri.rb', line 153
def path=(pth)
case scheme
when 'file','path' then self.fspath = pth
else self.urlpath = pth
end
end
|
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/rio/rl/uri.rb', line 167
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
|
159
|
# File 'lib/rio/rl/uri.rb', line 159
def scheme() uri.scheme end
|
139
140
141
|
# File 'lib/rio/rl/uri.rb', line 139
def to_s()
self.url
end
|
136
137
138
|
# File 'lib/rio/rl/uri.rb', line 136
def url()
self.uri.to_s
end
|
142
|
# File 'lib/rio/rl/uri.rb', line 142
def urlpath() uri.path end
|
#urlpath=(arg) ⇒ Object
143
144
145
146
|
# File 'lib/rio/rl/uri.rb', line 143
def urlpath=(arg)
uri.path = arg
end
|
180
181
182
183
184
185
|
# File 'lib/rio/rl/uri.rb', line 180
def urlroot()
return nil unless absolute?
cp = self.clone
cp.urlpath = self.pathroot
cp.url
end
|