Class: Files::Lock
- Inherits:
-
Object
- Object
- Files::Lock
- Defined in:
- lib/files.com/models/lock.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.create(path, params = {}, options = {}) ⇒ Object
Parameters: path (required) - string - Path timeout - int64 - Lock timeout length.
-
.delete(path, params = {}, options = {}) ⇒ Object
Parameters: token (required) - string - Lock token.
- .destroy(path, params = {}, options = {}) ⇒ Object
-
.list_for(path, params = {}, options = {}) ⇒ Object
Parameters: page - int64 - Current page number.
Instance Method Summary collapse
-
#delete(params = {}) ⇒ Object
Parameters: token (required) - string - Lock token.
-
#depth ⇒ Object
string - Lock depth (0 or infinity).
- #depth=(value) ⇒ Object
- #destroy(params = {}) ⇒ Object
-
#initialize(attributes = {}, options = {}) ⇒ Lock
constructor
A new instance of Lock.
-
#owner ⇒ Object
string - Owner of lock.
- #owner=(value) ⇒ Object
-
#path ⇒ Object
string - Path This must be slash-delimited, but it must neither start nor end with a slash.
- #path=(value) ⇒ Object
- #save ⇒ Object
-
#scope ⇒ Object
string - Lock scope(shared or exclusive).
- #scope=(value) ⇒ Object
-
#timeout ⇒ Object
int64 - Lock timeout.
- #timeout=(value) ⇒ Object
-
#token ⇒ Object
string - Lock token.
- #token=(value) ⇒ Object
-
#type ⇒ Object
string - Lock type.
- #type=(value) ⇒ Object
-
#user_id ⇒ Object
int64 - Lock creator user ID.
- #user_id=(value) ⇒ Object
-
#username ⇒ Object
string - Lock creator username.
- #username=(value) ⇒ Object
Constructor Details
#initialize(attributes = {}, options = {}) ⇒ Lock
Returns a new instance of Lock.
7 8 9 10 |
# File 'lib/files.com/models/lock.rb', line 7 def initialize(attributes = {}, = {}) @attributes = attributes || {} @options = || {} end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/files.com/models/lock.rb', line 5 def attributes @attributes end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/files.com/models/lock.rb', line 5 def @options end |
Class Method Details
.create(path, params = {}, options = {}) ⇒ Object
Parameters:
path (required) - string - Path
timeout - int64 - Lock timeout length
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/files.com/models/lock.rb', line 144 def self.create(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String) raise InvalidParameterError.new("Bad parameter: timeout must be an Integer") if params.dig(:timeout) and !params.dig(:timeout).is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path) response, = Api.send_request("/locks/#{Addressable::URI.encode_component(params[:path])}", :post, params, ) Lock.new(response.data, ) end |
.delete(path, params = {}, options = {}) ⇒ Object
Parameters:
token (required) - string - Lock token
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/files.com/models/lock.rb', line 157 def self.delete(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String) raise InvalidParameterError.new("Bad parameter: token must be an String") if params.dig(:token) and !params.dig(:token).is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path) raise MissingParameterError.new("Parameter missing: token") unless params.dig(:token) response, = Api.send_request("/locks/#{Addressable::URI.encode_component(params[:path])}", :delete, params, ) response.data end |
.destroy(path, params = {}, options = {}) ⇒ Object
169 170 171 |
# File 'lib/files.com/models/lock.rb', line 169 def self.destroy(path, params = {}, = {}) delete(path, params, ) end |
.list_for(path, params = {}, options = {}) ⇒ Object
Parameters:
page - int64 - Current page number.
per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended).
action - string - Deprecated: If set to `count` returns a count of matching records rather than the records themselves.
path (required) - string - Path to operate on.
include_children - boolean - Include locks from children objects?
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/files.com/models/lock.rb', line 126 def self.list_for(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: page must be an Integer") if params.dig(:page) and !params.dig(:page).is_a?(Integer) raise InvalidParameterError.new("Bad parameter: per_page must be an Integer") if params.dig(:per_page) and !params.dig(:per_page).is_a?(Integer) raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String) raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path) response, = Api.send_request("/locks/#{Addressable::URI.encode_component(params[:path])}", :get, params, ) response.data.map do |entity_data| Lock.new(entity_data, ) end end |
Instance Method Details
#delete(params = {}) ⇒ Object
Parameters:
token (required) - string - Lock token
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/files.com/models/lock.rb', line 95 def delete(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String) raise InvalidParameterError.new("Bad parameter: token must be an String") if params.dig(:token) and !params.dig(:token).is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path) raise MissingParameterError.new("Parameter missing: token") unless params.dig(:token) Api.send_request("/locks/#{Addressable::URI.encode_component(params[:path])}", :delete, params, @options) end |
#depth ⇒ Object
string - Lock depth (0 or infinity)
31 32 33 |
# File 'lib/files.com/models/lock.rb', line 31 def depth @attributes[:depth] end |
#depth=(value) ⇒ Object
35 36 37 |
# File 'lib/files.com/models/lock.rb', line 35 def depth=(value) @attributes[:depth] = value end |
#destroy(params = {}) ⇒ Object
107 108 109 |
# File 'lib/files.com/models/lock.rb', line 107 def destroy(params = {}) delete(params) end |
#owner ⇒ Object
string - Owner of lock. This can be any arbitrary string.
40 41 42 |
# File 'lib/files.com/models/lock.rb', line 40 def owner @attributes[:owner] end |
#owner=(value) ⇒ Object
44 45 46 |
# File 'lib/files.com/models/lock.rb', line 44 def owner=(value) @attributes[:owner] = value end |
#path ⇒ Object
string - Path This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
13 14 15 |
# File 'lib/files.com/models/lock.rb', line 13 def path @attributes[:path] end |
#path=(value) ⇒ Object
17 18 19 |
# File 'lib/files.com/models/lock.rb', line 17 def path=(value) @attributes[:path] = value end |
#save ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/files.com/models/lock.rb', line 111 def save if @attributes[:path] raise NotImplementedError.new("The Lock object doesn't support updates.") else new_obj = Lock.create(@attributes, @options) @attributes = new_obj.attributes end end |
#scope ⇒ Object
string - Lock scope(shared or exclusive)
49 50 51 |
# File 'lib/files.com/models/lock.rb', line 49 def scope @attributes[:scope] end |
#scope=(value) ⇒ Object
53 54 55 |
# File 'lib/files.com/models/lock.rb', line 53 def scope=(value) @attributes[:scope] = value end |
#timeout ⇒ Object
int64 - Lock timeout
22 23 24 |
# File 'lib/files.com/models/lock.rb', line 22 def timeout @attributes[:timeout] end |
#timeout=(value) ⇒ Object
26 27 28 |
# File 'lib/files.com/models/lock.rb', line 26 def timeout=(value) @attributes[:timeout] = value end |
#token ⇒ Object
string - Lock token. Use to release lock.
58 59 60 |
# File 'lib/files.com/models/lock.rb', line 58 def token @attributes[:token] end |
#token=(value) ⇒ Object
62 63 64 |
# File 'lib/files.com/models/lock.rb', line 62 def token=(value) @attributes[:token] = value end |
#type ⇒ Object
string - Lock type
67 68 69 |
# File 'lib/files.com/models/lock.rb', line 67 def type @attributes[:type] end |
#type=(value) ⇒ Object
71 72 73 |
# File 'lib/files.com/models/lock.rb', line 71 def type=(value) @attributes[:type] = value end |
#user_id ⇒ Object
int64 - Lock creator user ID
76 77 78 |
# File 'lib/files.com/models/lock.rb', line 76 def user_id @attributes[:user_id] end |
#user_id=(value) ⇒ Object
80 81 82 |
# File 'lib/files.com/models/lock.rb', line 80 def user_id=(value) @attributes[:user_id] = value end |
#username ⇒ Object
string - Lock creator username
85 86 87 |
# File 'lib/files.com/models/lock.rb', line 85 def username @attributes[:username] end |
#username=(value) ⇒ Object
89 90 91 |
# File 'lib/files.com/models/lock.rb', line 89 def username=(value) @attributes[:username] = value end |