class Pione::Location::DataLocation

Constants

KNOWN_ATTRS

Attributes

scheme[R]

@return [String]

location's scheme name
path[R]

@return [Pathname]

path of the location
uri[R]

@return [URI]

URI of the location

Public Class Methods

define(name, val) click to toggle source

Define a location’s attribute.

  • need_caching : whether the location needs to be cached or not

  • real_appendable : whether the location can appendable or not

  • writable : whether the location is writable or not

# File lib/pione/location/data-location.rb, line 28
def define(name, val)
  if DataLocation::KNOWN_ATTRS.include?(name)
    (@attr ||= Hash.new)[name] = val
  else
    raise ArgumentError.new(name)
  end
end
need_caching?() click to toggle source

Return true if the location needs caching.

# File lib/pione/location/data-location.rb, line 37
def need_caching?
  @attr[:need_caching]
end
new(uri) click to toggle source

Create a location with the URI.

@param uri [URI]

location URI
# File lib/pione/location/data-location.rb, line 65
def initialize(uri)
  @address = uri.to_s
  @uri = uri.kind_of?(URI::Generic) ? uri : URI.parse(uri)
  @path = Pathname.new(uri.path)
  raise ArgumentError.new(uri) unless @uri.scheme = scheme
end
real_appendable?() click to toggle source
# File lib/pione/location/data-location.rb, line 41
def real_appendable?
  @attr[:real_appendable]
end
set_scheme(name) click to toggle source

Declare the name as location scheme.

@param name [String]

scheme name
# File lib/pione/location/data-location.rb, line 17
def set_scheme(name)
  @scheme = name
  SCHEMES[name] = self
end
writable?() click to toggle source
# File lib/pione/location/data-location.rb, line 45
def writable?
  @writable
end

Public Instance Methods

+(name) click to toggle source

Create new location appended the name.

@param name [String]

filename or directory name

@return [BasicLocation]

new location
# File lib/pione/location/data-location.rb, line 93
def +(name)
  self.class.new(@uri.as_directory + name.to_s)
end
==(other) click to toggle source

@api private

# File lib/pione/location/data-location.rb, line 368
def ==(other)
  return false unless other.kind_of?(self.class)
  @uri == other.uri
end
append(data) click to toggle source

Append data to the location data.

@param data [String]

data content

@return [void]

# File lib/pione/location/data-location.rb, line 179
def append(data)
  if real_appendable?
    raise NotImplmentedError
  else
    _local = local
    _local.append(data)
    _local.copy(self)
  end
end
as_directory() click to toggle source

Create new location that has URI as a directory.

@return [BasicLocation]

new location
# File lib/pione/location/data-location.rb, line 101
def as_directory
  self.class.new(@uri.as_directory)
end
basename(suffix="") click to toggle source

Return the basename of the location.

@param suffix [String]

suffix name

@return [String]

basename
# File lib/pione/location/data-location.rb, line 111
def basename(suffix="")
  File.basename(@path, suffix)
end
cached?() click to toggle source

Return true if the location is cached.

@return [Boolean]

true if the location is cached
# File lib/pione/location/data-location.rb, line 147
def cached?
  System::FileCache.cached?(self)
end
copy(dest) click to toggle source

Copy location’s content to the destination.

@param dest [BasicLocation]

destination

@return [void]

# File lib/pione/location/data-location.rb, line 325
def copy(dest)
  raise NotImplementedError
end
create(data) click to toggle source

Creates a file at the location. If a file exists at the location aleady, it raises an exception.

@param data [String]

data content

@return [void]

# File lib/pione/location/data-location.rb, line 170
def create(data)
  raise NotImplementedError
end
ctime() click to toggle source

Return ctime of the location.

@return [Time]

ctime
# File lib/pione/location/data-location.rb, line 217
def ctime
  raise NotImplementedError
end
delete() click to toggle source

Delete data of the location.

@return [void]

# File lib/pione/location/data-location.rb, line 209
def delete
  raise NotImplementedError
end
directory?() click to toggle source

Return true if data at the location is a directory. When there exists no files and no direcotries, then return false.

@return [Boolean]

true if data at the location is a directory
# File lib/pione/location/data-location.rb, line 300
def directory?
  raise NotImplementedError
end
directory_entries() click to toggle source

Return directory entries of the location.

@return [Array<Location>]

directory entries of the location
# File lib/pione/location/data-location.rb, line 272
def directory_entries
  entries.select do |entry|
    entry.directory? and not(entry.path.basename == "." or entry.path.basename == "..")
  end
end
dirname() click to toggle source

Return the dirname of location. This method returns it as a location.

# File lib/pione/location/data-location.rb, line 124
def dirname
  rebuild(@path.dirname).as_directory
end
entries(&b) click to toggle source

Return entries of the location.

@return [Array<Location>]

entries of the location
# File lib/pione/location/data-location.rb, line 248
def entries(&b)
  raise NotImplementedError
end
exist?() click to toggle source

Return true if there is data in the location.

@return [Boolean]

if there is data in the location
# File lib/pione/location/data-location.rb, line 282
def exist?
  raise NotImplementedError
end
extname() click to toggle source

Return the extension name of location.

@return

the extension name of location
# File lib/pione/location/data-location.rb, line 119
def extname
  File.extname(basename)
end
file?() click to toggle source

Return true if data at the location is a file. When there exists no files and no directories, then return false.

@return [Boolean]

true if data at the location is a file
# File lib/pione/location/data-location.rb, line 291
def file?
  raise NotImplementedError
end
file_entries() click to toggle source

Return file entries of the location.

@return [Array<Location>]

file entries of the location
# File lib/pione/location/data-location.rb, line 264
def file_entries
  entries.select{|entry| entry.file?}
end
hash() click to toggle source

@api private

# File lib/pione/location/data-location.rb, line 375
def hash
  @uri.hash
end
inspect() click to toggle source

@api private

# File lib/pione/location/data-location.rb, line 362
def inspect
  "#<%s %s:%s>" % [self.class, scheme, @path.to_s]
end
Also aliased as: to_s
local() click to toggle source

Copy the content to temporary local location and return the location. If the scheme is local, return itself.

# File lib/pione/location/data-location.rb, line 74
def local
  if scheme == "local"
    self
  else
    Location[Temppath.create].tap {|tmp| copy(tmp) if exist?}
  end
end
local?() click to toggle source

Return true if scheme of the location is local.

# File lib/pione/location/data-location.rb, line 83
def local?
  scheme == "local"
end
mkdir() click to toggle source

Make the path a directory.

@return [void]

# File lib/pione/location/data-location.rb, line 307
def mkdir
  raise NotImplementedError
end
move(dest) click to toggle source

Move to the destination.

@param dest [BasicLocation]

destination

@return [void]

# File lib/pione/location/data-location.rb, line 316
def move(dest)
  raise NotImplementedError
end
mtime() click to toggle source

Return mtime of the location.

@return [Time]

mtime
# File lib/pione/location/data-location.rb, line 225
def mtime
  raise NotImplementedError
end
mtime=(time) click to toggle source

Set mtime of the location.

@return [void]

# File lib/pione/location/data-location.rb, line 232
def mtime=(time)
  raise NotImplementedError
end
read() click to toggle source

Read location data.

@return [String]

data content
# File lib/pione/location/data-location.rb, line 193
def read
  raise NotImplementedError
end
rebuild(path) click to toggle source

Rebuild location with the path.

@param path [Pathname]

new path

@return [Location]

location with new path
# File lib/pione/location/data-location.rb, line 134
def rebuild(path)
  scheme = @uri.scheme
  auth = @uri.user and @uri.password ? "%s:%s@" % [@uri.user, @uri.password] : ""
  host = @uri.host
  port = @uri.port ? ":%i" % @uri.port : ""
  path = path.expand_path("/").to_s
  Location["%s://%s%s%s%s" % [scheme, auth, host, port, path]]
end
rel_entries(option) click to toggle source

Return relative entries of the location.

@return [Array<String>]

entries of the location
# File lib/pione/location/data-location.rb, line 256
def rel_entries(option)
  raise NotImplementedError
end
sha1() click to toggle source

Return the digest string by SHA1.

@return [String]

hex-string of the file
# File lib/pione/location/data-location.rb, line 353
def sha1
  if file?
    Digest::SHA1.file(local.path)
  else
    raise InvalidFileOperation.new(self)
  end
end
size() click to toggle source

Return byte size of data in the location.

@return [Integer]

byte size of data
# File lib/pione/location/data-location.rb, line 240
def size
  raise NotImplementedError
end
to_s()
Alias for: inspect
turn(dest) click to toggle source

Move data to the destination and link self to it.

@param dest [BasicLocation]

destination

@return [void]

# File lib/pione/location/data-location.rb, line 345
def turn(dest)
  raise NotImplementedError
end
update(data) click to toggle source

Update with the data.

@param data [String]

new data content

@return [void]

# File lib/pione/location/data-location.rb, line 202
def update(data)
  raise NotImplementedError
end
write(data) click to toggle source

Write a data into the location.

@param data [String]

data content

@return [void]

# File lib/pione/location/data-location.rb, line 156
def write(data)
  if exist?
    update(data)
  else
    create(data)
  end
end