Class: Tilia::Dav::SimpleFile
- Defined in:
- lib/tilia/dav/simple_file.rb
Overview
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.
Instance Attribute Summary collapse
-
#contents ⇒ Object
File contents.
-
#mime_type ⇒ Object
A mimetype, such as ‘text/plain’ or ‘text/html’.
-
#name ⇒ Object
Returns the node name for this file.
Instance Method Summary collapse
-
#content_type ⇒ Object
Returns the mime-type for a file.
-
#etag ⇒ Object
Returns the ETag for a file.
-
#get ⇒ Object
Returns the data.
-
#initialize(name, contents, mime_type = nil) ⇒ SimpleFile
constructor
Creates this node.
-
#size ⇒ Object
Returns the size of the file, in bytes.
Methods inherited from File
Methods included from IFile
Methods included from INode
Methods inherited from Node
Constructor Details
#initialize(name, contents, mime_type = nil) ⇒ SimpleFile
Creates this node
The name of the node must be passed, as well as the contents of the file.
33 34 35 36 37 |
# 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 |
Instance Attribute Details
#contents ⇒ Object
File contents
13 14 15 |
# File 'lib/tilia/dav/simple_file.rb', line 13 def contents @contents end |
#mime_type ⇒ Object
A mimetype, such as ‘text/plain’ or ‘text/html’
23 24 25 |
# File 'lib/tilia/dav/simple_file.rb', line 23 def mime_type @mime_type end |
#name ⇒ Object
Returns the node name for this file.
This name is used to construct the url.
18 19 20 |
# File 'lib/tilia/dav/simple_file.rb', line 18 def name @name end |
Instance Method Details
#content_type ⇒ Object
Returns the mime-type for a file
If null is returned, we’ll assume application/octet-stream
77 78 79 |
# File 'lib/tilia/dav/simple_file.rb', line 77 def content_type @mime_type end |
#etag ⇒ Object
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
69 70 71 |
# File 'lib/tilia/dav/simple_file.rb', line 69 def etag '"' + Digest::SHA1.hexdigest(@contents) + '"' end |
#get ⇒ Object
Returns the data
This method may either return a string or a readable stream resource
51 52 53 |
# File 'lib/tilia/dav/simple_file.rb', line 51 def get @contents end |
#size ⇒ Object
Returns the size of the file, in bytes.
58 59 60 |
# File 'lib/tilia/dav/simple_file.rb', line 58 def size @contents.bytes.size end |