Class: Calligraphy::Resource

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

Overview

Resource base class.

All custom resource classes should be inherited from Resource and should implement the relevant methods needed for the desired level of WebDAV support.

Direct Known Subclasses

FileResource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource: nil, req: nil, mount: nil, root_dir: nil) ⇒ Resource

:nodoc:



15
16
17
18
19
20
21
# File 'lib/calligraphy/resource/resource.rb', line 15

def initialize(resource: nil, req: nil, mount: nil, root_dir: nil)
  @full_request_path = req&.original_url
  @mount_point = mount || req&.path&.tap { |s| s.slice! resource }
  @request_body = req&.body&.read || ''
  @request_path = mount.nil? ? resource : resource.split(mount)[-1]
  @root_dir = root_dir
end

Instance Attribute Details

#client_nonceObject

Returns the value of attribute client_nonce.



10
11
12
# File 'lib/calligraphy/resource/resource.rb', line 10

def client_nonce
  @client_nonce
end

#contentsObject

Returns the value of attribute contents.



10
11
12
# File 'lib/calligraphy/resource/resource.rb', line 10

def contents
  @contents
end

#full_request_pathObject (readonly)

Returns the value of attribute full_request_path.



11
12
13
# File 'lib/calligraphy/resource/resource.rb', line 11

def full_request_path
  @full_request_path
end

#mount_pointObject (readonly)

Returns the value of attribute mount_point.



11
12
13
# File 'lib/calligraphy/resource/resource.rb', line 11

def mount_point
  @mount_point
end

#request_bodyObject (readonly)

Returns the value of attribute request_body.



11
12
13
# File 'lib/calligraphy/resource/resource.rb', line 11

def request_body
  @request_body
end

#request_pathObject (readonly)

Returns the value of attribute request_path.



11
12
13
# File 'lib/calligraphy/resource/resource.rb', line 11

def request_path
  @request_path
end

#root_dirObject (readonly)

Returns the value of attribute root_dir.



11
12
13
# File 'lib/calligraphy/resource/resource.rb', line 11

def root_dir
  @root_dir
end

#updated_atObject

Returns the value of attribute updated_at.



10
11
12
# File 'lib/calligraphy/resource/resource.rb', line 10

def updated_at
  @updated_at
end

Instance Method Details

#ancestor_exist?Boolean

Responsible for returning a boolean value indicating if an ancestor exists for the resource.

Used in COPY and MKCOL requests.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

def ancestor_exist?
  raise NotImplementedError
end

#collection?Boolean

Responsible for returning a boolean value indicating if the resource is a collection.

Used in DELETE, MKCOL, MOVE, and PUT requests.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/calligraphy/resource/resource.rb', line 35

def collection?
  raise NotImplementedError
end

#copy(_options) ⇒ Object

Responsible for creating a duplicate of the resource in ‘options` (see section 9.8 of RFC4918).

Used in COPY and MOVE (which inherits from COPY) requests.

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/calligraphy/resource/resource.rb', line 55

def copy(_options)
  raise NotImplementedError
end

#copy_options(_options) ⇒ Object

Responsible for returning a hash with keys indicating if the resource can be copied, if an ancestor exists, or if the copy destinatin is locked.

Return hash should contain ‘can_copy`, `ancestor_exist`, and `locked` keys with boolean values.

Used in COPY and MOVE (which inherits from COPY) requests.

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/calligraphy/resource/resource.rb', line 47

def copy_options(_options)
  raise NotImplementedError
end

#create_collectionObject

Responsible for creating a new collection based on the resource (see section 9.3 of RFC4918).

Used in MKCOL requests.

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/calligraphy/resource/resource.rb', line 63

def create_collection
  raise NotImplementedError
end

#dav_complianceObject

A DAV-compliant resource can advertise several classes of compliance. ‘dav_compliance` is responsible for returning the classes of WebDAV compliance that the resource supports (see section 18 of RFC4918).

Used in OPTIONS requests.



72
73
74
# File 'lib/calligraphy/resource/resource.rb', line 72

def dav_compliance
  '1, 2, 3'
end

#delete_collectionObject

Responsible for deleting a resource collection (see section 9.6 of RFC4918).

Used in DELETE and MOVE requests.

Raises:

  • (NotImplementedError)


80
81
82
# File 'lib/calligraphy/resource/resource.rb', line 80

def delete_collection
  raise NotImplementedError
end

#etagObject

Responsible for returning unique identifier used to create an etag.

Used in precondition validation, as well as GET, HEAD, and PROPFIND requests.

Raises:

  • (NotImplementedError)


88
89
90
# File 'lib/calligraphy/resource/resource.rb', line 88

def etag
  raise NotImplementedError
end

#exists?Boolean

Responsible for indicating if the resource already exists.

Used in DELETE, LOCK, MKCOL, and MOVE requests.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


95
96
97
# File 'lib/calligraphy/resource/resource.rb', line 95

def exists?
  raise NotImplementedError
end

#lock(_nodes, _depth = 'infinity') ⇒ Object

Responsible for creating a lock on the resource (see section 9.10 of RFC4918).

Used in LOCK requests.

Raises:

  • (NotImplementedError)


103
104
105
# File 'lib/calligraphy/resource/resource.rb', line 103

def lock(_nodes, _depth = 'infinity')
  raise NotImplementedError
end

#lock_is_exclusive?Boolean

Responsible for indicating if a resource lock is exclusive.

Used in LOCK requests.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


110
111
112
# File 'lib/calligraphy/resource/resource.rb', line 110

def lock_is_exclusive?
  raise NotImplementedError
end

#locked?Boolean

Responsible for indicating if a resource is current locked.

Used in LOCK requests.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


117
118
119
# File 'lib/calligraphy/resource/resource.rb', line 117

def locked?
  raise NotImplementedError
end

#locked_to_user?(_headers = nil) ⇒ Boolean

Responsible for indicating if a resource is locked to the current user.

Used in DELETE, LOCK, MOVE, PROPPATCH, and PUT requests.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

def locked_to_user?(_headers = nil)
  raise NotImplementedError
end

#propfind(_nodes) ⇒ Object

Responsible for handling the retrieval of properties defined on the resource (see section 9.1 of RFC4918).

Used in PROPFIND requests.

Raises:

  • (NotImplementedError)


132
133
134
# File 'lib/calligraphy/resource/resource.rb', line 132

def propfind(_nodes)
  raise NotImplementedError
end

#proppatch(_nodes) ⇒ Object

Responsible for handling the addition and/or removal of properties defined on the resource through a PROPPATCH request (see section 9.2 of RFC4918).

Used in PROPPATCH requests.

Raises:

  • (NotImplementedError)


141
142
143
# File 'lib/calligraphy/resource/resource.rb', line 141

def proppatch(_nodes)
  raise NotImplementedError
end

#readObject

Responsible for setting and returning the contents of a resource if it is readable (see section 9.4 of RFC4918).

Used in GET requests.

Raises:

  • (NotImplementedError)


149
150
151
# File 'lib/calligraphy/resource/resource.rb', line 149

def read
  raise NotImplementedError
end

#readable?Boolean

Responsible for indicating if a resource is readable.

Used in GET and HEAD requests.

Returns:

  • (Boolean)


156
157
158
# File 'lib/calligraphy/resource/resource.rb', line 156

def readable?
  exists? && !collection?
end

#refresh_lockObject

Responsible for refreshing locks (see section 9.10.2 of RFC4918).

Used in LOCK requests.

Raises:

  • (NotImplementedError)


163
164
165
# File 'lib/calligraphy/resource/resource.rb', line 163

def refresh_lock
  raise NotImplementedError
end

#unlock(_token) ⇒ Object

Responsible for unlocking a resource lock (see section 9.11 of RFC4918).

Used in UNLOCK requests.

Raises:

  • (NotImplementedError)


170
171
172
# File 'lib/calligraphy/resource/resource.rb', line 170

def unlock(_token)
  raise NotImplementedError
end

#write(_contents = @request_body.to_s) ⇒ Object

Responsible for writing contents to a resource (see section 9.7 of RFC4918).

Used in PUT requests.

Raises:

  • (NotImplementedError)


178
179
180
# File 'lib/calligraphy/resource/resource.rb', line 178

def write(_contents = @request_body.to_s)
  raise NotImplementedError
end