Class: Pageflow::EditLock
Overview
rubocop:todo Style/Documentation
Defined Under Namespace
Classes: Error, HeldByOtherSessionError, HeldByOtherUserError, NotHeldError, Null
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Method Details
#acquire(current_user, options = {}) ⇒ Object
45
46
47
48
49
50
51
|
# File 'app/models/pageflow/edit_lock.rb', line 45
def acquire(current_user, options = {})
verify!(current_user, options)
rescue Error
raise unless options[:force] || timed_out?
entry.create_edit_lock(user: current_user)
end
|
#held_by?(user) ⇒ Boolean
33
34
35
|
# File 'app/models/pageflow/edit_lock.rb', line 33
def held_by?(user)
self.user == user
end
|
#matches?(id) ⇒ Boolean
37
38
39
|
# File 'app/models/pageflow/edit_lock.rb', line 37
def matches?(id)
self.id == id.to_i
end
|
#release(current_user) ⇒ Object
53
54
55
56
57
|
# File 'app/models/pageflow/edit_lock.rb', line 53
def release(current_user)
return unless user == current_user
destroy
end
|
#timed_out? ⇒ Boolean
41
42
43
|
# File 'app/models/pageflow/edit_lock.rb', line 41
def timed_out?
Time.now > updated_at + EditLock.time_to_live
end
|
#verify!(current_user, options) ⇒ Object
59
60
61
62
63
64
|
# File 'app/models/pageflow/edit_lock.rb', line 59
def verify!(current_user, options)
raise HeldByOtherUserError, user unless held_by?(current_user)
raise HeldByOtherSessionError unless matches?(options[:id])
touch
end
|