Class: Calligraphy::Resource
- Inherits:
-
Object
- Object
- Calligraphy::Resource
- 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
Instance Attribute Summary collapse
-
#client_nonce ⇒ Object
Returns the value of attribute client_nonce.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#full_request_path ⇒ Object
readonly
Returns the value of attribute full_request_path.
-
#mount_point ⇒ Object
readonly
Returns the value of attribute mount_point.
-
#request_body ⇒ Object
readonly
Returns the value of attribute request_body.
-
#request_path ⇒ Object
readonly
Returns the value of attribute request_path.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
-
#ancestor_exist? ⇒ Boolean
Responsible for returning a boolean value indicating if an ancestor exists for the resource.
-
#collection? ⇒ Boolean
Responsible for returning a boolean value indicating if the resource is a collection.
-
#copy(_options) ⇒ Object
Responsible for creating a duplicate of the resource in ‘options` (see section 9.8 of RFC4918).
-
#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.
-
#create_collection ⇒ Object
Responsible for creating a new collection based on the resource (see section 9.3 of RFC4918).
-
#dav_compliance ⇒ Object
A DAV-compliant resource can advertise several classes of compliance.
-
#delete_collection ⇒ Object
Responsible for deleting a resource collection (see section 9.6 of RFC4918).
-
#etag ⇒ Object
Responsible for returning unique identifier used to create an etag.
-
#exists? ⇒ Boolean
Responsible for indicating if the resource already exists.
-
#initialize(resource: nil, req: nil, mount: nil, root_dir: nil) ⇒ Resource
constructor
:nodoc:.
-
#lock(_nodes, _depth = 'infinity') ⇒ Object
Responsible for creating a lock on the resource (see section 9.10 of RFC4918).
-
#lock_is_exclusive? ⇒ Boolean
Responsible for indicating if a resource lock is exclusive.
-
#locked? ⇒ Boolean
Responsible for indicating if a resource is current locked.
-
#locked_to_user?(_headers = nil) ⇒ Boolean
Responsible for indicating if a resource is locked to the current user.
-
#propfind(_nodes) ⇒ Object
Responsible for handling the retrieval of properties defined on the resource (see section 9.1 of RFC4918).
-
#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).
-
#read ⇒ Object
Responsible for setting and returning the contents of a resource if it is readable (see section 9.4 of RFC4918).
-
#readable? ⇒ Boolean
Responsible for indicating if a resource is readable.
-
#refresh_lock ⇒ Object
Responsible for refreshing locks (see section 9.10.2 of RFC4918).
-
#unlock(_token) ⇒ Object
Responsible for unlocking a resource lock (see section 9.11 of RFC4918).
-
#write(_contents = @request_body.to_s) ⇒ Object
Responsible for writing contents to a resource (see section 9.7 of RFC4918).
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_nonce ⇒ Object
Returns the value of attribute client_nonce.
10 11 12 |
# File 'lib/calligraphy/resource/resource.rb', line 10 def client_nonce @client_nonce end |
#contents ⇒ Object
Returns the value of attribute contents.
10 11 12 |
# File 'lib/calligraphy/resource/resource.rb', line 10 def contents @contents end |
#full_request_path ⇒ Object (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_point ⇒ Object (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_body ⇒ Object (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_path ⇒ Object (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_dir ⇒ Object (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_at ⇒ Object
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.
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.
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.
55 56 57 |
# File 'lib/calligraphy/resource/resource.rb', line 55 def copy() 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.
47 48 49 |
# File 'lib/calligraphy/resource/resource.rb', line 47 def () raise NotImplementedError end |
#create_collection ⇒ Object
Responsible for creating a new collection based on the resource (see section 9.3 of RFC4918).
Used in MKCOL requests.
63 64 65 |
# File 'lib/calligraphy/resource/resource.rb', line 63 def create_collection raise NotImplementedError end |
#dav_compliance ⇒ Object
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_collection ⇒ Object
Responsible for deleting a resource collection (see section 9.6 of RFC4918).
Used in DELETE and MOVE requests.
80 81 82 |
# File 'lib/calligraphy/resource/resource.rb', line 80 def delete_collection raise NotImplementedError end |
#etag ⇒ Object
Responsible for returning unique identifier used to create an etag.
Used in precondition validation, as well as GET, HEAD, and PROPFIND requests.
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.
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.
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.
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.
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.
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.
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.
141 142 143 |
# File 'lib/calligraphy/resource/resource.rb', line 141 def proppatch(_nodes) raise NotImplementedError end |
#read ⇒ Object
Responsible for setting and returning the contents of a resource if it is readable (see section 9.4 of RFC4918).
Used in GET requests.
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.
156 157 158 |
# File 'lib/calligraphy/resource/resource.rb', line 156 def readable? exists? && !collection? end |
#refresh_lock ⇒ Object
Responsible for refreshing locks (see section 9.10.2 of RFC4918).
Used in LOCK requests.
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.
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.
178 179 180 |
# File 'lib/calligraphy/resource/resource.rb', line 178 def write(_contents = @request_body.to_s) raise NotImplementedError end |