Class: PostLocker
- Inherits:
-
Object
- Object
- PostLocker
- Defined in:
- lib/post_locker.rb
Instance Method Summary collapse
-
#initialize(post, user) ⇒ PostLocker
constructor
A new instance of PostLocker.
- #lock ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize(post, user) ⇒ PostLocker
Returns a new instance of PostLocker.
4 5 6 |
# File 'lib/post_locker.rb', line 4 def initialize(post, user) @post, @user = post, user end |
Instance Method Details
#lock ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/post_locker.rb', line 8 def lock Guardian.new(@user).ensure_can_lock_post!(@post) Post.transaction do @post.update_column(:locked_by_id, @user.id) StaffActionLogger.new(@user).log_post_lock(@post, locked: true) end end |
#unlock ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/post_locker.rb', line 17 def unlock Guardian.new(@user).ensure_can_lock_post!(@post) Post.transaction do @post.update_column(:locked_by_id, nil) StaffActionLogger.new(@user).log_post_lock(@post, locked: false) end end |