Class: RackDAV::Resource
- Inherits:
-
Object
- Object
- RackDAV::Resource
- Defined in:
- lib/rack_dav/resource.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #child(name, option = {}) ⇒ Object
-
#children ⇒ Object
If this is a collection, return the child resources.
-
#collection? ⇒ Boolean
Is this resource a collection?.
-
#content_length ⇒ Object
Return the size in bytes for this resource.
-
#content_type ⇒ Object
Return the mime type of this resource.
-
#copy(dest) ⇒ Object
HTTP COPY request.
-
#creation_date ⇒ Object
Return the creation time.
-
#delete ⇒ Object
HTTP DELETE request.
- #descendants ⇒ Object
- #display_name ⇒ Object
-
#etag ⇒ Object
Return an Etag, an unique hash value for this resource.
-
#exist? ⇒ Boolean
Does this recource exist?.
-
#get(request, response) ⇒ Object
HTTP GET request.
- #get_property(name) ⇒ Object
-
#initialize(path, options) ⇒ Resource
constructor
A new instance of Resource.
-
#last_modified ⇒ Object
Return the time of last modification.
-
#last_modified=(time) ⇒ Object
Set the time of last modification.
-
#make_collection ⇒ Object
HTTP MKCOL request.
-
#move(dest) ⇒ Object
HTTP MOVE request.
- #name ⇒ Object
- #parent ⇒ Object
-
#post(request, response) ⇒ Object
HTTP POST request.
- #property_names ⇒ Object
-
#put(request, response) ⇒ Object
HTTP PUT request.
- #remove_property(name) ⇒ Object
-
#resource_type ⇒ Object
Return the resource type.
- #set_property(name, value) ⇒ Object
Constructor Details
#initialize(path, options) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 |
# File 'lib/rack_dav/resource.rb', line 6 def initialize(path, ) @path = path @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/rack_dav/resource.rb', line 4 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/rack_dav/resource.rb', line 4 def path @path end |
Instance Method Details
#==(other) ⇒ Object
116 117 118 |
# File 'lib/rack_dav/resource.rb', line 116 def ==(other) path == other.path end |
#child(name, option = {}) ⇒ Object
128 129 130 |
# File 'lib/rack_dav/resource.rb', line 128 def child(name, option={}) self.class.new(path + '/' + name, ) end |
#children ⇒ Object
If this is a collection, return the child resources.
12 13 14 |
# File 'lib/rack_dav/resource.rb', line 12 def children raise NotImplementedError end |
#collection? ⇒ Boolean
Is this resource a collection?
17 18 19 |
# File 'lib/rack_dav/resource.rb', line 17 def collection? raise NotImplementedError end |
#content_length ⇒ Object
Return the size in bytes for this resource.
62 63 64 |
# File 'lib/rack_dav/resource.rb', line 62 def content_length raise NotImplementedError end |
#content_type ⇒ Object
Return the mime type of this resource.
57 58 59 |
# File 'lib/rack_dav/resource.rb', line 57 def content_type raise NotImplementedError end |
#copy(dest) ⇒ Object
HTTP COPY request.
Copy this resource to given destination resource.
97 98 99 |
# File 'lib/rack_dav/resource.rb', line 97 def copy(dest) raise NotImplementedError end |
#creation_date ⇒ Object
Return the creation time.
27 28 29 |
# File 'lib/rack_dav/resource.rb', line 27 def creation_date raise NotImplementedError end |
#delete ⇒ Object
HTTP DELETE request.
Delete this resource.
90 91 92 |
# File 'lib/rack_dav/resource.rb', line 90 def delete raise NotImplementedError end |
#descendants ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/rack_dav/resource.rb', line 169 def descendants list = [] children.each do |child| list << child list.concat(child.descendants) end list end |
#display_name ⇒ Object
124 125 126 |
# File 'lib/rack_dav/resource.rb', line 124 def display_name name end |
#etag ⇒ Object
Return an Etag, an unique hash value for this resource.
42 43 44 |
# File 'lib/rack_dav/resource.rb', line 42 def etag raise NotImplementedError end |
#exist? ⇒ Boolean
Does this recource exist?
22 23 24 |
# File 'lib/rack_dav/resource.rb', line 22 def exist? raise NotImplementedError end |
#get(request, response) ⇒ Object
HTTP GET request.
Write the content of the resource to the response.body.
69 70 71 |
# File 'lib/rack_dav/resource.rb', line 69 def get(request, response) raise NotImplementedError end |
#get_property(name) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rack_dav/resource.rb', line 136 def get_property(name) case name when 'resourcetype' then resource_type when 'displayname' then display_name when 'creationdate' then creation_date.xmlschema when 'getcontentlength' then content_length.to_s when 'getcontenttype' then content_type when 'getetag' then etag when 'getlastmodified' then last_modified.httpdate end end |
#last_modified ⇒ Object
Return the time of last modification.
32 33 34 |
# File 'lib/rack_dav/resource.rb', line 32 def last_modified raise NotImplementedError end |
#last_modified=(time) ⇒ Object
Set the time of last modification.
37 38 39 |
# File 'lib/rack_dav/resource.rb', line 37 def last_modified=(time) raise NotImplementedError end |
#make_collection ⇒ Object
HTTP MKCOL request.
Create this resource as collection.
112 113 114 |
# File 'lib/rack_dav/resource.rb', line 112 def make_collection raise NotImplementedError end |
#move(dest) ⇒ Object
HTTP MOVE request.
Move this resource to given destination resource.
104 105 106 107 |
# File 'lib/rack_dav/resource.rb', line 104 def move(dest) copy(dest) delete end |
#name ⇒ Object
120 121 122 |
# File 'lib/rack_dav/resource.rb', line 120 def name File.basename(path) end |
#parent ⇒ Object
163 164 165 166 167 |
# File 'lib/rack_dav/resource.rb', line 163 def parent elements = @path.scan(/[^\/]+/) return nil if elements.empty? self.class.new('/' + elements[0..-2].to_a.join('/'), @options) end |
#post(request, response) ⇒ Object
HTTP POST request.
Usually forbidden.
83 84 85 |
# File 'lib/rack_dav/resource.rb', line 83 def post(request, response) raise NotImplementedError end |
#property_names ⇒ Object
132 133 134 |
# File 'lib/rack_dav/resource.rb', line 132 def property_names %w(creationdate displayname getlastmodified getetag resourcetype getcontenttype getcontentlength) end |
#put(request, response) ⇒ Object
HTTP PUT request.
Save the content of the request.body.
76 77 78 |
# File 'lib/rack_dav/resource.rb', line 76 def put(request, response) raise NotImplementedError end |
#remove_property(name) ⇒ Object
159 160 161 |
# File 'lib/rack_dav/resource.rb', line 159 def remove_property(name) raise HTTPStatus::Forbidden end |
#resource_type ⇒ Object
Return the resource type.
If this is a collection, return REXML::Element.new(‘D:collection’)
50 51 52 53 54 |
# File 'lib/rack_dav/resource.rb', line 50 def resource_type if collection? REXML::Element.new('D:collection') end end |
#set_property(name, value) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rack_dav/resource.rb', line 148 def set_property(name, value) case name when 'resourcetype' then self.resource_type = value when 'getcontenttype' then self.content_type = value when 'getetag' then self.etag = value when 'getlastmodified' then self.last_modified = Time.httpdate(value) end rescue ArgumentError raise HTTPStatus::Conflict end |