Class: Lita::Handlers::LockerEvents
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::LockerEvents
- Includes:
- Locker::Label, Locker::Misc, Locker::Regex, Locker::Resource
- Defined in:
- lib/lita/handlers/locker_events.rb
Overview
Event-related handlers
Constant Summary
Constants included from Locker::Regex
Locker::Regex::COMMENT_REGEX, Locker::Regex::LABELS_REGEX, Locker::Regex::LABEL_REGEX, Locker::Regex::LOCK_REGEX, Locker::Regex::RESOURCES_REGEX, Locker::Regex::RESOURCE_REGEX, Locker::Regex::UNLOCK_REGEX, Locker::Regex::USER_REGEX
Instance Method Summary collapse
Methods included from Locker::Misc
#failed, #locked, #success, #unlocked, #user_locks
Methods included from Locker::Label
#label_dependencies, #label_ownership
Instance Method Details
#lock_attempt(payload) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lita/handlers/locker_events.rb', line 15 def lock_attempt(payload) label = payload[:label] user = Lita::User.find_by_id(payload[:user_id]) request_id = payload[:request_id] return unless Label.exists?(label) l = Label.new(label) if l.lock!(user.id) robot.trigger(:lock_success, request_id: request_id) else robot.trigger(:lock_failure, request_id: request_id) end end |
#unlock_attempt(payload) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lita/handlers/locker_events.rb', line 29 def unlock_attempt(payload) label = payload[:label] request_id = payload[:request_id] return unless Label.exists?(label) l = Label.new(label) if l.unlock! robot.trigger(:unlock_success, request_id: request_id) else robot.trigger(:unlock_failure, request_id: request_id) end end |