Class: Lita::Handlers::LockerResources
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::LockerResources
- Includes:
- Locker::Label, Locker::Misc, Locker::Regex, Locker::Resource
- Defined in:
- lib/lita/handlers/locker_resources.rb
Overview
Resource-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
- #create(response) ⇒ Object
- #delete(response) ⇒ Object
- #list(response) ⇒ Object
- #show(response) ⇒ Object
Methods included from Locker::Misc
#failed, #locked, #success, #unlocked, #user_locks
Methods included from Locker::Label
#label_dependencies, #label_ownership
Instance Method Details
#create(response) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/lita/handlers/locker_resources.rb', line 65 def create(response) names = response.match_data['resources'].split(/,\s*/) results = [] names.each do |name| if Resource.exists?(name) results <<= t('resource.exists', name: name) else Resource.create(name) results <<= t('resource.created', name: name) end end response.reply(results.join(', ')) end |
#delete(response) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/lita/handlers/locker_resources.rb', line 81 def delete(response) names = response.match_data['resources'].split(/,\s*/) results = [] names.each do |name| if Resource.exists?(name) Resource.delete(name) results <<= t('resource.deleted', name: name) else results <<= t('resource.does_not_exist', name: name) end end response.reply(results.join(', ')) end |
#list(response) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lita/handlers/locker_resources.rb', line 46 def list(response) after 0 do should_rate_limit = false Resource.list.each_slice(5) do |slice| if should_rate_limit sleep 3 else should_rate_limit = true end slice.each do |r| res = Resource.new(r) response.reply(t('resource.desc', name: r, state: res.state.value)) end end end end |
#show(response) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/lita/handlers/locker_resources.rb', line 97 def show(response) name = response.match_data['resource'] return response.reply(t('resource.does_not_exist', name: name)) unless Resource.exists?(name) r = Resource.new(name) resp = t('resource.desc', name: name, state: r.state.value) if r.labels.count > 0 resp += ', used by: ' r.labels.each do |label| resp += Label.new(label).id end end response.reply(resp) end |