Class: Valkyrie::Persistence::OptimisticLockToken
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::OptimisticLockToken
- Defined in:
- lib/valkyrie/persistence/optimistic_lock_token.rb
Instance Attribute Summary collapse
-
#adapter_id ⇒ Object
readonly
Returns the value of attribute adapter_id.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
-
.deserialize(serialized_token) ⇒ Object
Deserializing lock tokens means that we can then use the adapter id and the lock token value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(adapter_id:, token:) ⇒ OptimisticLockToken
constructor
A new instance of OptimisticLockToken.
-
#serialize ⇒ Object
(also: #to_s)
Serializing lock tokens makes them easy to cast to strings and back.
Constructor Details
#initialize(adapter_id:, token:) ⇒ OptimisticLockToken
Returns a new instance of OptimisticLockToken.
8 9 10 11 |
# File 'lib/valkyrie/persistence/optimistic_lock_token.rb', line 8 def initialize(adapter_id:, token:) @adapter_id = adapter_id @token = token end |
Instance Attribute Details
#adapter_id ⇒ Object (readonly)
Returns the value of attribute adapter_id.
4 5 6 |
# File 'lib/valkyrie/persistence/optimistic_lock_token.rb', line 4 def adapter_id @adapter_id end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/valkyrie/persistence/optimistic_lock_token.rb', line 4 def token @token end |
Class Method Details
.deserialize(serialized_token) ⇒ Object
Deserializing lock tokens means that we can then use the adapter id and the lock token value
27 28 29 30 31 32 |
# File 'lib/valkyrie/persistence/optimistic_lock_token.rb', line 27 def self.deserialize(serialized_token) token_parts = serialized_token.to_s.split(":", 3) adapter_id = token_parts[1] token = token_parts[2] new(adapter_id: Valkyrie::ID.new(adapter_id), token: token) end |
Instance Method Details
#==(other) ⇒ Object
20 21 22 23 24 |
# File 'lib/valkyrie/persistence/optimistic_lock_token.rb', line 20 def ==(other) return false unless other.is_a?(self.class) return false unless adapter_id == other.adapter_id token == other.token end |
#serialize ⇒ Object Also known as: to_s
Serializing lock tokens makes them easy to cast to strings and back. Primary use case is for embedding one in a form as a hidden field
15 16 17 |
# File 'lib/valkyrie/persistence/optimistic_lock_token.rb', line 15 def serialize "lock_token:#{adapter_id}:#{token}" end |