Class: RackWebDAV::Resource
- Inherits:
-
Object
- Object
- RackWebDAV::Resource
- Defined in:
- lib/rack-webdav/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 ⇒ Object
HTTP GET request.
- #get_property(name) ⇒ Object
-
#initialize(path, request, response, 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.
- #lockable? ⇒ Boolean
-
#make_collection ⇒ Object
HTTP MKCOL request.
-
#move(dest) ⇒ Object
HTTP MOVE request.
- #name ⇒ Object
- #parent ⇒ Object
-
#post ⇒ Object
HTTP POST request.
- #property_names ⇒ Object
-
#put ⇒ Object
HTTP PUT request.
- #remove_property(name) ⇒ Object
-
#resource_type ⇒ Object
Return the resource type.
- #set_property(name, value) ⇒ Object
Constructor Details
#initialize(path, request, response, options) ⇒ Resource
Returns a new instance of Resource.
7 8 9 10 11 12 |
# File 'lib/rack-webdav/resource.rb', line 7 def initialize(path, request, response, ) @path = path @request = request @response = response @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/rack-webdav/resource.rb', line 5 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/rack-webdav/resource.rb', line 5 def path @path end |
Instance Method Details
#==(other) ⇒ Object
118 119 120 |
# File 'lib/rack-webdav/resource.rb', line 118 def ==(other) path == other.path end |
#child(name, option = {}) ⇒ Object
130 131 132 |
# File 'lib/rack-webdav/resource.rb', line 130 def child(name, option={}) self.class.new(path + '/' + name, @request, @response, ) end |
#children ⇒ Object
If this is a collection, return the child resources.
15 16 17 |
# File 'lib/rack-webdav/resource.rb', line 15 def children raise NotImplementedError end |
#collection? ⇒ Boolean
Is this resource a collection?
20 21 22 |
# File 'lib/rack-webdav/resource.rb', line 20 def collection? raise NotImplementedError end |
#content_length ⇒ Object
Return the size in bytes for this resource.
64 65 66 |
# File 'lib/rack-webdav/resource.rb', line 64 def content_length raise NotImplementedError end |
#content_type ⇒ Object
Return the mime type of this resource.
59 60 61 |
# File 'lib/rack-webdav/resource.rb', line 59 def content_type raise NotImplementedError end |
#copy(dest) ⇒ Object
HTTP COPY request.
Copy this resource to given destination resource.
99 100 101 |
# File 'lib/rack-webdav/resource.rb', line 99 def copy(dest) raise NotImplementedError end |
#creation_date ⇒ Object
Return the creation time.
30 31 32 |
# File 'lib/rack-webdav/resource.rb', line 30 def creation_date raise NotImplementedError end |
#delete ⇒ Object
HTTP DELETE request.
Delete this resource.
92 93 94 |
# File 'lib/rack-webdav/resource.rb', line 92 def delete raise NotImplementedError end |
#descendants ⇒ Object
179 180 181 182 183 184 185 186 |
# File 'lib/rack-webdav/resource.rb', line 179 def descendants list = [] children.each do |child| list << child list.concat(child.descendants) end list end |
#display_name ⇒ Object
126 127 128 |
# File 'lib/rack-webdav/resource.rb', line 126 def display_name name end |
#etag ⇒ Object
Return an Etag, an unique hash value for this resource.
45 46 47 |
# File 'lib/rack-webdav/resource.rb', line 45 def etag raise NotImplementedError end |
#exist? ⇒ Boolean
Does this recource exist?
25 26 27 |
# File 'lib/rack-webdav/resource.rb', line 25 def exist? raise NotImplementedError end |
#get ⇒ Object
HTTP GET request.
Write the content of the resource to the response.body.
71 72 73 |
# File 'lib/rack-webdav/resource.rb', line 71 def get raise NotImplementedError end |
#get_property(name) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rack-webdav/resource.rb', line 142 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 else self.get_custom_property(name) if self.respond_to?(:get_custom_property) end end |
#last_modified ⇒ Object
Return the time of last modification.
35 36 37 |
# File 'lib/rack-webdav/resource.rb', line 35 def last_modified raise NotImplementedError end |
#last_modified=(time) ⇒ Object
Set the time of last modification.
40 41 42 |
# File 'lib/rack-webdav/resource.rb', line 40 def last_modified=(time) raise NotImplementedError end |
#lockable? ⇒ Boolean
134 135 136 |
# File 'lib/rack-webdav/resource.rb', line 134 def lockable? self.respond_to?(:lock) && self.respond_to?(:unlock) end |
#make_collection ⇒ Object
HTTP MKCOL request.
Create this resource as collection.
114 115 116 |
# File 'lib/rack-webdav/resource.rb', line 114 def make_collection raise NotImplementedError end |
#move(dest) ⇒ Object
HTTP MOVE request.
Move this resource to given destination resource.
106 107 108 109 |
# File 'lib/rack-webdav/resource.rb', line 106 def move(dest) copy(dest) delete end |
#name ⇒ Object
122 123 124 |
# File 'lib/rack-webdav/resource.rb', line 122 def name File.basename(path) end |
#parent ⇒ Object
173 174 175 176 177 |
# File 'lib/rack-webdav/resource.rb', line 173 def parent elements = @path.scan(/[^\/]+/) return nil if elements.empty? self.class.new('/' + elements[0..-2].to_a.join('/'), @options) end |
#post ⇒ Object
HTTP POST request.
Usually forbidden.
85 86 87 |
# File 'lib/rack-webdav/resource.rb', line 85 def post raise NotImplementedError end |
#property_names ⇒ Object
138 139 140 |
# File 'lib/rack-webdav/resource.rb', line 138 def property_names %w(creationdate displayname getlastmodified getetag resourcetype getcontenttype getcontentlength) end |
#put ⇒ Object
HTTP PUT request.
Save the content of the request.body.
78 79 80 |
# File 'lib/rack-webdav/resource.rb', line 78 def put raise NotImplementedError end |
#remove_property(name) ⇒ Object
169 170 171 |
# File 'lib/rack-webdav/resource.rb', line 169 def remove_property(name) raise HTTPStatus::Forbidden if property_names.include?(name) end |
#resource_type ⇒ Object
Return the resource type.
If this is a collection, return a collection element
52 53 54 55 56 |
# File 'lib/rack-webdav/resource.rb', line 52 def resource_type if collection? Nokogiri::XML::fragment('<D:collection xmlns:D="DAV:"/>').children.first end end |
#set_property(name, value) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/rack-webdav/resource.rb', line 155 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) else self.set_custom_property(name, value) if self.respond_to?(:set_custom_property) end rescue Errno::EOPNOTSUPP # nothing done rescue ArgumentError raise HTTPStatus::Conflict end |