Class: RackDAV::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_dav/resource.rb

Direct Known Subclasses

FileResource

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @path = path
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/rack_dav/resource.rb', line 4

def options
  @options
end

#pathObject (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, options)
end

#childrenObject

If this is a collection, return the child resources.

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/rack_dav/resource.rb', line 12

def children
  raise NotImplementedError
end

#collection?Boolean

Is this resource a collection?

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/rack_dav/resource.rb', line 17

def collection?
  raise NotImplementedError
end

#content_lengthObject

Return the size in bytes for this resource.

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/rack_dav/resource.rb', line 62

def content_length
  raise NotImplementedError
end

#content_typeObject

Return the mime type of this resource.

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


97
98
99
# File 'lib/rack_dav/resource.rb', line 97

def copy(dest)
  raise NotImplementedError
end

#creation_dateObject

Return the creation time.

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/rack_dav/resource.rb', line 27

def creation_date
  raise NotImplementedError
end

#deleteObject

HTTP DELETE request.

Delete this resource.

Raises:

  • (NotImplementedError)


90
91
92
# File 'lib/rack_dav/resource.rb', line 90

def delete
  raise NotImplementedError
end

#descendantsObject



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_nameObject



124
125
126
# File 'lib/rack_dav/resource.rb', line 124

def display_name
  name
end

#etagObject

Return an Etag, an unique hash value for this resource.

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/rack_dav/resource.rb', line 42

def etag
  raise NotImplementedError
end

#exist?Boolean

Does this recource exist?

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


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_modifiedObject

Return the time of last modification.

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/rack_dav/resource.rb', line 37

def last_modified=(time)
  raise NotImplementedError
end

#make_collectionObject

HTTP MKCOL request.

Create this resource as collection.

Raises:

  • (NotImplementedError)


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

#nameObject



120
121
122
# File 'lib/rack_dav/resource.rb', line 120

def name
  File.basename(path)
end

#parentObject



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.

Raises:

  • (NotImplementedError)


83
84
85
# File 'lib/rack_dav/resource.rb', line 83

def post(request, response)
  raise NotImplementedError
end

#property_namesObject



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.

Raises:

  • (NotImplementedError)


76
77
78
# File 'lib/rack_dav/resource.rb', line 76

def put(request, response)
  raise NotImplementedError
end

#remove_property(name) ⇒ Object

Raises:

  • (HTTPStatus::Forbidden)


159
160
161
# File 'lib/rack_dav/resource.rb', line 159

def remove_property(name)
  raise HTTPStatus::Forbidden
end

#resource_typeObject

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