class Tilia::Dav::SimpleFile
The 'SimpleFile' class is used to easily add read-only immutable files to the directory structure. One usecase would be to add a 'readme.txt' to a root of a webserver with some standard content.
Attributes
File
contents
@var string
A mimetype, such as 'text/plain' or 'text/html'
@var string
Name of this resource
@var string
Public Class Methods
Creates this node
The name of the node must be passed, as well as the contents of the file.
@param string name @param string contents @param string|nil mime_type
# File lib/tilia/dav/simple_file.rb, line 33 def initialize(name, contents, mime_type = nil) @name = name @contents = contents @mime_type = mime_type end
Public Instance Methods
Returns the mime-type for a file
If null is returned, we'll assume application/octet-stream @return string
# File lib/tilia/dav/simple_file.rb, line 77 def content_type @mime_type end
Returns the ETag for a file
An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
Return null if the ETag can not effectively be determined @return string
# File lib/tilia/dav/simple_file.rb, line 69 def etag '"' + Digest::SHA1.hexdigest(@contents) + '"' end
Returns the data
This method may either return a string or a readable stream resource
@return mixed
# File lib/tilia/dav/simple_file.rb, line 51 def get @contents end
Returns the size of the file, in bytes.
@return int
# File lib/tilia/dav/simple_file.rb, line 58 def size @contents.bytes.size end