Skip to content

Commit

Permalink
Start to clear out older function-based ways.
Browse files Browse the repository at this point in the history
  • Loading branch information
esigler committed Jan 8, 2015
1 parent f38ff49 commit e222ded
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ LineLength:
Max: 120

AbcSize:
Max: 25
Max: 30
6 changes: 3 additions & 3 deletions lib/lita/handlers/locker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Locker < Handler
def lock(response)
name = response.matches[0][0]

return response.reply(t('label.does_not_exist', name: name)) unless label_exists?(name)
return response.reply(t('label.does_not_exist', name: name)) unless Label.exists?(name)
m = label_membership(name)
return response.reply(t('label.no_resources', name: name)) unless m.count > 0
return response.reply(t('label.lock', name: name)) if lock_label!(name, response.user, nil)
Expand All @@ -54,14 +54,14 @@ def lock(response)

def unlock(response)
name = response.matches[0][0]
return response.reply(t('subject.does_not_exist', name: name)) unless label_exists?(name)
return response.reply(t('subject.does_not_exist', name: name)) unless Label.exists?(name)
return response.reply(t('label.is_unlocked', name: name)) unless label_locked?(name)
response.reply(attempt_unlock(name, response.user))
end

def steal(response)
name = response.matches[0][0]
return response.reply(t('subject.does_not_exist', name: name)) unless label_exists?(name)
return response.reply(t('subject.does_not_exist', name: name)) unless Label.exists?(name)
return response.reply(t('steal.already_unlocked', label: name)) unless label_locked?(name)
response.reply(attempt_steal(name, response.user))
end
Expand Down
4 changes: 2 additions & 2 deletions lib/lita/handlers/locker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def lock_attempt(payload)
user = Lita::User.find_by_id(payload[:user_id])
request_id = payload[:request_id]

if label_exists?(label) && lock_label!(label, user, nil)
if Label.exists?(label) && lock_label!(label, user, nil)
robot.trigger(:lock_success, request_id: request_id)
else
robot.trigger(:lock_failure, request_id: request_id)
Expand All @@ -28,7 +28,7 @@ def unlock_attempt(payload)
label = payload[:label]
request_id = payload[:request_id]

if label_exists?(label) && unlock_label!(label)
if Label.exists?(label) && unlock_label!(label)
robot.trigger(:unlock_success, request_id: request_id)
else
robot.trigger(:unlock_failure, request_id: request_id)
Expand Down
13 changes: 6 additions & 7 deletions lib/lita/handlers/locker_labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ class LockerLabels < Handler

def list(response)
labels.sort.each do |n|
name = n.sub('label_', '')
l = label(name)
response.reply(t('label.desc', name: name, state: l.state.value))
l = Label.new(n)
response.reply(t('label.desc', name: n, state: l.state.value))
end
end

Expand All @@ -70,7 +69,7 @@ def create(response)

def delete(response)
name = response.matches[0][0]
if delete_label(name)
if Label.exists?(name) && Label.delete(name)
response.reply(t('label.deleted', name: name))
else
response.reply(t('label.does_not_exist', name: name))
Expand All @@ -79,7 +78,7 @@ def delete(response)

def show(response)
name = response.matches[0][0]
return response.reply(t('label.does_not_exist', name: name)) unless label_exists?(name)
return response.reply(t('label.does_not_exist', name: name)) unless Label.exists?(name)
members = label_membership(name)
return response.reply(t('label.has_no_resources', name: name)) unless members.count > 0
res = []
Expand All @@ -92,7 +91,7 @@ def show(response)
def add(response)
resource_name = response.matches[0][0]
label_name = response.matches[0][1]
return response.reply(t('label.does_not_exist', name: label_name)) unless label_exists?(label_name)
return response.reply(t('label.does_not_exist', name: label_name)) unless Label.exists?(label_name)
return response.reply(t('resource.does_not_exist', name: resource_name)) unless resource_exists?(resource_name)
add_resource_to_label(label_name, resource_name)
response.reply(t('label.resource_added', label: label_name, resource: resource_name))
Expand All @@ -101,7 +100,7 @@ def add(response)
def remove(response)
resource_name = response.matches[0][0]
label_name = response.matches[0][1]
return response.reply(t('label.does_not_exist', name: label_name)) unless label_exists?(label_name)
return response.reply(t('label.does_not_exist', name: label_name)) unless Label.exists?(label_name)
return response.reply(t('resource.does_not_exist', name: resource_name)) unless resource_exists?(resource_name)
members = label_membership(label_name)
if members.include?(resource_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/lita/handlers/locker_misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LockerMisc < Handler

def status(response)
name = response.matches[0][0]
if label_exists?(name)
if Label.exists?(name)
l = label(name)
if l.owner_id.value != ''
o = Lita::User.find_by_id(l.owner_id.value)
Expand Down
4 changes: 0 additions & 4 deletions lib/locker/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ def labels
Label.list
end

def label_exists?(name)
Label.exists?(name)
end

def label_locked?(name)
l = Label.new(name)
l.locked?
Expand Down

0 comments on commit e222ded

Please sign in to comment.