class Tilia::Dav::SimpleFile

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

contents[RW]

File contents

@var string

mime_type[RW]

A mimetype, such as 'text/plain' or 'text/html'

@var string

name[RW]

Name of this resource

@var string

Public Class Methods

new(name, contents, mime_type = nil) click to toggle source

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

content_type() click to toggle source

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
etag() click to toggle source

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
get() click to toggle source

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
size() click to toggle source

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