Class: RIO::RL::URIBase

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

Direct Known Subclasses

PathBase

Instance Attribute Summary collapse

Attributes inherited from Base

#fs

Class Method Summary collapse

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, #fspath, is_riorl?, #length, #rl, split_riorl, subscheme, #to_rl

Constructor Details

#initialize(u, *args) ⇒ URIBase

Returns a new instance of URIBase.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rio/rl/uri.rb', line 36

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 = ::Alt::URI::create(:scheme => 'file', :path => fs.getwd+'/')
  end
  @uri.path = '/' if @uri.absolute? and @uri.path == ''
end

Instance Attribute Details

#uriObject

Returns the value of attribute uri.



35
36
37
# File 'lib/rio/rl/uri.rb', line 35

def uri
  @uri
end

Class Method Details

.parse(*a) ⇒ Object



138
139
140
141
# File 'lib/rio/rl/uri.rb', line 138

def self.parse(*a)
  parms = splitrl(a.shift) || []
  new(*(parms+a))
end

Instance Method Details

#_get_base_from_arg(arg) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rio/rl/uri.rb', line 72

def _get_base_from_arg(arg)
  case arg
  when RIO::Rio
    arg.abs.to_uri
  when URIBase
    arg.abs.uri
  when ::Alt::URI::Base
    arg if arg.absolute?
  when ::String 
    uri_from_string_(arg) || ::Alt::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



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rio/rl/uri.rb', line 86

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?

Returns:

  • (Boolean)


103
104
105
# File 'lib/rio/rl/uri.rb', line 103

def absolute?()
  uri.absolute?
end

#arg0_info_(arg0, *args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rio/rl/uri.rb', line 49

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 ::Alt::URI::Base 
    vuri = arg0
  when ::String 
    vuri = uri_from_string_(arg0) || ::Alt::URI.parse(arg0)
  else
    raise(ArgumentError,"'#{arg0}'[#{arg0.class}] can not be used to create a Rio")
  end
  [vuri,vbase,vfs]
end

#baseObject



160
161
162
# File 'lib/rio/rl/uri.rb', line 160

def base()
  @base || self.uri
end

#base=(arg) ⇒ Object



163
164
165
# File 'lib/rio/rl/uri.rb', line 163

def base=(arg)
  @base = _uri(arg)
end

#hostObject



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

def host() uri.host end

#host=(arg) ⇒ Object



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

def host=(arg) uri.host = arg end

#init_from_args_(arg0, *args) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/rio/rl/uri.rb', line 65

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



98
99
100
101
102
# File 'lib/rio/rl/uri.rb', line 98

def initialize_copy(*args)
  super
  @uri = @uri.clone unless @uri.nil?
  @base = @base.clone unless @base.nil?
end

#join(*args) ⇒ Object



166
167
168
169
# File 'lib/rio/rl/uri.rb', line 166

def join(*args)
  return self if args.empty?
  join_(args.map{ |arg| arg.to_s})
end

#opaqueObject



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

def opaque()
  u = uri.clone
  u.query = nil
  u.to_s.sub(/^#{SCHEME}:/,'')
end

#openfs_Object



107
108
109
110
# File 'lib/rio/rl/uri.rb', line 107

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

#pathObject



121
122
123
124
125
126
# File 'lib/rio/rl/uri.rb', line 121

def path()
  case scheme
  when 'file','path' then fspath()
  else urlpath()
  end
end

#path=(pth) ⇒ Object



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

def path=(pth)
  uri.path = pth
end

#pathrootObject



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rio/rl/uri.rb', line 142

def pathroot()
  u = uri.clone
  case scheme
  when 'file'
    if self.urlpath =~ %r'^(/[a-zA-Z]):' then $1+':/'
    else '/'
    end
  else
    u.path = '/'
    u.to_s
  end
end

#schemeObject



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

def scheme() uri.scheme end

#to_sObject



114
115
116
# File 'lib/rio/rl/uri.rb', line 114

def to_s()
  self.url
end

#urlObject



111
112
113
# File 'lib/rio/rl/uri.rb', line 111

def url()
  self.uri.to_s
end

#urlpathObject



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

def urlpath() uri.path end

#urlpath=(arg) ⇒ Object



118
119
120
# File 'lib/rio/rl/uri.rb', line 118

def urlpath=(arg) 
  uri.path = arg 
end

#urlrootObject



154
155
156
157
158
159
# File 'lib/rio/rl/uri.rb', line 154

def urlroot()
  return nil unless absolute?
  cp = self.clone
  cp.urlpath = self.pathroot
  cp.url
end