Class: Path::URL

Inherits:
Path show all
Defined in:
lib/epitools/path.rb

Overview

A wrapper for URL objects.

Constant Summary

Constants inherited from Path

AUTOGENERATED_CLASS_METHODS, BINARY_EXTENSION, PATH_SEPARATOR

Instance Attribute Summary collapse

Attributes inherited from Path

#base, #dirs, #ext

Instance Method Summary collapse

Methods inherited from Path

#/, #<=>, #==, #=~, [], #[], #[]=, #append, #atime, #atime=, #attrs, #attrs=, #backup!, #backup_file, #broken_symlink?, cd, #cd, #child_of?, #chmod, #chmod_R, #chown, #chown_R, #cp, #cp_r, #ctime, #deflate, #dir, #dir=, #dir?, #each_chunk, #each_line, #endswith, escape, #executable?, #exists?, expand_path, #exts, #file?, #filename, #filename=, getfattr, glob, #grep, #gunzip!, #gzip!, home, #inflate, #initialize_copy, #inspect, #ln_s, ln_s, ls, #ls, #ls_R, #ls_dirs, #ls_files, ls_r, #ls_r, #lstat, #magic, #md5, #mimetype, #mimetype_from_ext, #mode, #mtime, #mtime=, #mv, #mv!, #name, #nicelines, #numbered_backup!, #numbered_backup_file, #owner?, #parent, #parent_of?, #parse, #path, #path=, popd, pushd, pwd, #read_bson, #read_csv, #read_html, #read_json, #read_marshal, #read_xml, #read_yaml, #readable?, #realpath, #relative, #relative?, #relative_to, #reload!, #rename, #rename!, #reset!, #rm, setfattr, #sha1, #sha2, #siblings, #size, #sort_attrs, #startswith, #symlink?, #symlink_target, tmpdir, tmpfile, #to_Path, #touch, #truncate, #type, #unmarshal, #update, #url?, which, #writable?, #write, #write_bson, #write_json, #write_marshal, #write_yaml

Constructor Details

#initialize(uri, hints = {}) ⇒ URL

TODO: only include certain methods from Path (delegate style)

(eg: remove commands that write)


1380
1381
1382
1383
# File 'lib/epitools/path.rb', line 1380

def initialize(uri, hints={})
  @uri = URI.parse(uri)
  self.path = @uri.path
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



1374
1375
1376
# File 'lib/epitools/path.rb', line 1374

def uri
  @uri
end

Instance Method Details

#hostObject

…and this is: ‘host.com’



1406
# File 'lib/epitools/path.rb', line 1406

def host; uri.host; end

#join(other) ⇒ Object



1424
1425
1426
# File 'lib/epitools/path.rb', line 1424

def join(other)
  Path.new URI.join(path, other).to_s
end

#open(mode = "r", &block) ⇒ Object

…and ‘path` is /path/filename.ext



1431
1432
1433
1434
1435
1436
1437
1438
# File 'lib/epitools/path.rb', line 1431

def open(mode="r", &block)
  require 'open-uri'
  if block_given?
    open(to_s, mode, &block)
  else
    open(to_s, mode)
  end
end

#portObject

…and this is: 80



1411
# File 'lib/epitools/path.rb', line 1411

def port; uri.port; end

#queryObject

…and this is: {param1: value1, param2: value2, …etc… }



1416
1417
1418
1419
1420
1421
1422
# File 'lib/epitools/path.rb', line 1416

def query
  if query = uri.query
    query.to_params
  else
    nil
  end
end

#read(*args) ⇒ Object

Note: open is already aliased to io in parent class.



1441
1442
1443
1444
1445
1446
1447
1448
1449
# File 'lib/epitools/path.rb', line 1441

def read(*args)
  require 'open-uri'
  case scheme
  when /https?/i
    io.read(*args)
  else
    raise "No connector for #{scheme} yet. Please fix!"
  end
end

#schemeObject Also known as: protocol

…this is: ‘http’



1400
# File 'lib/epitools/path.rb', line 1400

def scheme; uri.scheme; end

#to_sObject



1394
# File 'lib/epitools/path.rb', line 1394

def to_s; uri.to_s; end

#uri?Boolean

Returns:

  • (Boolean)


1385
1386
1387
# File 'lib/epitools/path.rb', line 1385

def uri?
  true
end