Class: RIO::RL::URIBase

Inherits:
WithPath show all
Defined in:
lib/rio/rl/uri.rb

Direct Known Subclasses

FTP::RL, FTP::Stream::RL, HTTP::RL, PathBase

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_

Methods included from Error::NotImplemented

#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)
  # u should be a ::URI or something that can be parsed to one
  #p callstr('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

#uriObject

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)
  #p "_get_base: #{arg.inspect}"
  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)
      #@base.path.sub!(%r{/*$},'/')
    end
    if fs = opts[:fs]
      @fs = fs
    end
  end
  args
end

#absolute?Boolean Also known as: abs?

Returns:

  • (Boolean)


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)
  #p "arg0_info_(#{arg0.inspect},#{args.inspect})"
  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

#baseObject



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)
  #p "uri.rb:base= arg=#{arg.inspect}"
  @base = _uri(arg)
end

#hostObject



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)
  #p "init_from_args_(#{arg0.inspect})"
  #p callstr('init_from_args_',arg0.inspect,args)
  vuri,vbase,vfs = self.arg0_info_(arg0,*args)
  #p vuri
  @uri = vuri
  #p args unless args.nil? || args.empty?
  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

#opaqueObject



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

#openfs_Object



128
129
130
131
# File 'lib/rio/rl/uri.rb', line 128

def openfs_()
  #p callstr('openfs_')
  @fs || RIO::FS::Native.create()
end

#pathObject



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

#pathrootObject



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

#schemeObject



155
# File 'lib/rio/rl/uri.rb', line 155

def scheme() uri.scheme end

#to_sObject



135
136
137
# File 'lib/rio/rl/uri.rb', line 135

def to_s()
  self.url
end

#urlObject



132
133
134
# File 'lib/rio/rl/uri.rb', line 132

def url()
  self.uri.to_s
end

#urlpathObject



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) 
  #p uri,arg
  uri.path = arg 
end

#urlrootObject



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