Class: Pione::Location::DataLocation
- Inherits:
-
BasicLocation
- Object
- BasicLocation
- Pione::Location::DataLocation
- Defined in:
- lib/pione/location/data-location.rb
Direct Known Subclasses
Constant Summary collapse
- KNOWN_ATTRS =
[:need_caching, :real_appendable, :writable]
Class Attribute Summary collapse
-
.scheme ⇒ String
readonly
Location's scheme name.
Instance Attribute Summary collapse
-
#path ⇒ Pathname
readonly
Path of the location.
-
#uri ⇒ URI
readonly
URI of the location.
Attributes inherited from BasicLocation
Class Method Summary collapse
-
.define(name, val) ⇒ Object
Define a location's attribute.
-
.need_caching? ⇒ Boolean
Return true if the location needs caching.
- .real_appendable? ⇒ Boolean
-
.set_scheme(name) ⇒ Object
Declare the name as location scheme.
- .writable? ⇒ Boolean
Instance Method Summary collapse
-
#+(name) ⇒ BasicLocation
Create new location appended the name.
- #==(other) ⇒ Object (also: #eql?) private
-
#append(data) ⇒ void
Append data to the location data.
-
#as_directory ⇒ BasicLocation
Create new location that has URI as a directory.
-
#basename(suffix = "") ⇒ String
Return the basename of the location.
-
#cached? ⇒ Boolean
Return true if the location is cached.
-
#copy(dest) ⇒ void
Copy location's content to the destination.
-
#create(data) ⇒ void
Creates a file at the location.
-
#ctime ⇒ Time
Return ctime of the location.
-
#delete ⇒ void
Delete data of the location.
-
#directory? ⇒ Boolean
Return true if data at the location is a directory.
-
#directory_entries ⇒ Array<Location>
Return directory entries of the location.
-
#dirname ⇒ Object
Return the dirname of location.
-
#entries(&b) ⇒ Array<Location>
Return entries of the location.
-
#exist? ⇒ Boolean
Return true if there is data in the location.
-
#extname ⇒ Object
Return the extension name of location.
-
#file? ⇒ Boolean
Return true if data at the location is a file.
-
#file_entries ⇒ Array<Location>
Return file entries of the location.
- #hash ⇒ Object private
-
#initialize(uri) ⇒ DataLocation
constructor
Create a location with the URI.
- #inspect ⇒ Object (also: #to_s) private
-
#link(dest) ⇒ void
Link to the destination.
-
#local ⇒ Object
Copy the content to temporary local location and return the location.
-
#local? ⇒ Boolean
Return true if scheme of the location is local.
-
#mkdir ⇒ void
Make the path a directory.
-
#move(dest) ⇒ void
Move to the destination.
-
#mtime ⇒ Time
Return mtime of the location.
-
#mtime=(time) ⇒ void
Set mtime of the location.
-
#read ⇒ String
Read location data.
-
#rebuild(path) ⇒ Location
Rebuild location with the path.
-
#rel_entries(option) ⇒ Array<String>
Return relative entries of the location.
-
#sha1 ⇒ String
Return the digest string by SHA1.
-
#size ⇒ Integer
Return byte size of data in the location.
-
#turn(dest) ⇒ void
Move data to the destination and link self to it.
-
#update(data) ⇒ void
Update with the data.
-
#write(data) ⇒ void
Write a data into the location.
Methods inherited from BasicLocation
Constructor Details
#initialize(uri) ⇒ DataLocation
Create a location with the URI.
65 66 67 68 69 70 |
# 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 |
Class Attribute Details
.scheme ⇒ String (readonly)
Returns location's scheme name.
11 12 13 |
# File 'lib/pione/location/data-location.rb', line 11 def scheme @scheme end |
Instance Attribute Details
#path ⇒ Pathname (readonly)
Returns path of the location.
59 60 61 |
# File 'lib/pione/location/data-location.rb', line 59 def path @path end |
#uri ⇒ URI (readonly)
Returns URI of the location.
55 56 57 |
# File 'lib/pione/location/data-location.rb', line 55 def uri @uri end |
Class Method Details
.define(name, val) ⇒ Object
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
28 29 30 31 32 33 34 |
# 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? ⇒ Boolean
Return true if the location needs caching.
37 38 39 |
# File 'lib/pione/location/data-location.rb', line 37 def need_caching? @attr[:need_caching] end |
.real_appendable? ⇒ Boolean
41 42 43 |
# File 'lib/pione/location/data-location.rb', line 41 def real_appendable? @attr[:real_appendable] end |
.set_scheme(name) ⇒ Object
Declare the name as location scheme.
17 18 19 20 |
# File 'lib/pione/location/data-location.rb', line 17 def set_scheme(name) @scheme = name SCHEMES[name] = self end |
.writable? ⇒ Boolean
45 46 47 |
# File 'lib/pione/location/data-location.rb', line 45 def writable? @writable end |
Instance Method Details
#+(name) ⇒ BasicLocation
Create new location appended the name.
93 94 95 |
# File 'lib/pione/location/data-location.rb', line 93 def +(name) self.class.new(@uri.as_directory + name.to_s) end |
#==(other) ⇒ Object Also known as: eql?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
368 369 370 371 |
# 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) ⇒ void
This method returns an undefined value.
Append data to the location data.
179 180 181 182 183 184 185 186 187 |
# 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 ⇒ BasicLocation
Create new location that has URI as a directory.
101 102 103 |
# File 'lib/pione/location/data-location.rb', line 101 def as_directory self.class.new(@uri.as_directory) end |
#basename(suffix = "") ⇒ String
Return the basename of the location.
111 112 113 |
# File 'lib/pione/location/data-location.rb', line 111 def basename(suffix="") File.basename(@path, suffix) end |
#cached? ⇒ Boolean
Return true if the location is cached.
147 148 149 |
# File 'lib/pione/location/data-location.rb', line 147 def cached? System::FileCache.cached?(self) end |
#copy(dest) ⇒ void
This method returns an undefined value.
Copy location's content to the destination.
325 326 327 |
# File 'lib/pione/location/data-location.rb', line 325 def copy(dest) raise NotImplementedError end |
#create(data) ⇒ void
This method returns an undefined value.
Creates a file at the location. If a file exists at the location aleady, it raises an exception.
170 171 172 |
# File 'lib/pione/location/data-location.rb', line 170 def create(data) raise NotImplementedError end |
#ctime ⇒ Time
Return ctime of the location.
217 218 219 |
# File 'lib/pione/location/data-location.rb', line 217 def ctime raise NotImplementedError end |
#delete ⇒ void
This method returns an undefined value.
Delete data of the location.
209 210 211 |
# File 'lib/pione/location/data-location.rb', line 209 def delete raise NotImplementedError end |
#directory? ⇒ Boolean
Return true if data at the location is a directory. When there exists no files and no direcotries, then return false.
300 301 302 |
# File 'lib/pione/location/data-location.rb', line 300 def directory? raise NotImplementedError end |
#directory_entries ⇒ Array<Location>
Return directory entries of the location.
272 273 274 275 276 |
# 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 ⇒ Object
Return the dirname of location. This method returns it as a location.
124 125 126 |
# File 'lib/pione/location/data-location.rb', line 124 def dirname rebuild(@path.dirname).as_directory end |
#entries(&b) ⇒ Array<Location>
Return entries of the location.
248 249 250 |
# File 'lib/pione/location/data-location.rb', line 248 def entries(&b) raise NotImplementedError end |
#exist? ⇒ Boolean
Return true if there is data in the location.
282 283 284 |
# File 'lib/pione/location/data-location.rb', line 282 def exist? raise NotImplementedError end |
#extname ⇒ Object
Return the extension name of location.
119 120 121 |
# File 'lib/pione/location/data-location.rb', line 119 def extname File.extname(basename) end |
#file? ⇒ Boolean
Return true if data at the location is a file. When there exists no files and no directories, then return false.
291 292 293 |
# File 'lib/pione/location/data-location.rb', line 291 def file? raise NotImplementedError end |
#file_entries ⇒ Array<Location>
Return file entries of the location.
264 265 266 |
# File 'lib/pione/location/data-location.rb', line 264 def file_entries entries.select{|entry| entry.file?} end |
#hash ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
375 376 377 |
# File 'lib/pione/location/data-location.rb', line 375 def hash @uri.hash end |
#inspect ⇒ Object Also known as: to_s
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
362 363 364 |
# File 'lib/pione/location/data-location.rb', line 362 def inspect "#<%s %s:%s>" % [self.class, scheme, @path.to_s] end |
#link(dest) ⇒ void
This method returns an undefined value.
Link to the destination. If the location scheme is same to destination, create link by a symbolic link or lightweight copy method. If not, copy it simply.
336 337 338 |
# File 'lib/pione/location/data-location.rb', line 336 def link(dest) raise NotImplementedError end |
#local ⇒ Object
Copy the content to temporary local location and return the location. If the scheme is local, return itself.
74 75 76 77 78 79 80 |
# 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? ⇒ Boolean
Return true if scheme of the location is local.
83 84 85 |
# File 'lib/pione/location/data-location.rb', line 83 def local? scheme == "local" end |
#mkdir ⇒ void
This method returns an undefined value.
Make the path a directory.
307 308 309 |
# File 'lib/pione/location/data-location.rb', line 307 def mkdir raise NotImplementedError end |
#move(dest) ⇒ void
This method returns an undefined value.
Move to the destination.
316 317 318 |
# File 'lib/pione/location/data-location.rb', line 316 def move(dest) raise NotImplementedError end |
#mtime ⇒ Time
Return mtime of the location.
225 226 227 |
# File 'lib/pione/location/data-location.rb', line 225 def mtime raise NotImplementedError end |
#mtime=(time) ⇒ void
This method returns an undefined value.
Set mtime of the location.
232 233 234 |
# File 'lib/pione/location/data-location.rb', line 232 def mtime=(time) raise NotImplementedError end |
#read ⇒ String
Read location data.
193 194 195 |
# File 'lib/pione/location/data-location.rb', line 193 def read raise NotImplementedError end |
#rebuild(path) ⇒ Location
Rebuild location with the path.
134 135 136 137 138 139 140 141 |
# 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.("/").to_s Location["%s://%s%s%s%s" % [scheme, auth, host, port, path]] end |
#rel_entries(option) ⇒ Array<String>
Return relative entries of the location.
256 257 258 |
# File 'lib/pione/location/data-location.rb', line 256 def rel_entries(option) raise NotImplementedError end |
#sha1 ⇒ String
Return the digest string by SHA1.
353 354 355 356 357 358 359 |
# 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 ⇒ Integer
Return byte size of data in the location.
240 241 242 |
# File 'lib/pione/location/data-location.rb', line 240 def size raise NotImplementedError end |
#turn(dest) ⇒ void
This method returns an undefined value.
Move data to the destination and link self to it.
345 346 347 |
# File 'lib/pione/location/data-location.rb', line 345 def turn(dest) raise NotImplementedError end |
#update(data) ⇒ void
This method returns an undefined value.
Update with the data.
202 203 204 |
# File 'lib/pione/location/data-location.rb', line 202 def update(data) raise NotImplementedError end |
#write(data) ⇒ void
This method returns an undefined value.
Write a data into the location.
156 157 158 159 160 161 162 |
# File 'lib/pione/location/data-location.rb', line 156 def write(data) if exist? update(data) else create(data) end end |