Class: Pageflow::EditLock
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pageflow::EditLock
show all
- Defined in:
- app/models/pageflow/edit_lock.rb
Defined Under Namespace
Classes: Error, HeldByOtherSessionError, HeldByOtherUserError, NotHeldError, Null
Constant Summary
collapse
- TIME_TO_LIVE =
10.seconds
Instance Method Summary
collapse
Instance Method Details
#aquire(current_user, options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'app/models/pageflow/edit_lock.rb', line 39
def aquire(current_user, options = {})
verify!(current_user, options)
rescue Error
if options[:force] || timed_out?
entry.create_edit_lock(:user => current_user)
else
raise
end
end
|
#held_by?(user) ⇒ Boolean
27
28
29
|
# File 'app/models/pageflow/edit_lock.rb', line 27
def held_by?(user)
self.user == user
end
|
#matches?(id) ⇒ Boolean
31
32
33
|
# File 'app/models/pageflow/edit_lock.rb', line 31
def matches?(id)
self.id == id.to_i
end
|
#release(current_user) ⇒ Object
49
50
51
52
53
|
# File 'app/models/pageflow/edit_lock.rb', line 49
def release(current_user)
if user == current_user
destroy
end
end
|
#timed_out? ⇒ Boolean
35
36
37
|
# File 'app/models/pageflow/edit_lock.rb', line 35
def timed_out?
Time.now > self.updated_at + TIME_TO_LIVE
end
|
#verify!(current_user, options) ⇒ Object