class Lita::Commands::EmptyGroups

Public Instance Methods

name() click to toggle source
# File lib/lita/commands/empty_groups.rb, line 6
def name
  'empty-groups'
end
run(robot, target, gateway, opts = {}) click to toggle source
# File lib/lita/commands/empty_groups.rb, line 10
def run(robot, target, gateway, opts = {})
  msg = build_msg(gateway)
  robot.send_message(target, msg) if msg
  robot.send_message(target, "No groups found") if msg.nil? && opts[:negative_ack]
end

Private Instance Methods

build_msg(gateway) click to toggle source
# File lib/lita/commands/empty_groups.rb, line 18
def build_msg(gateway)
  groups = empty_groups(gateway)

  if groups.any?
    msg = "The following groups have no members, which may result in undelivered email.\n"
    msg += groups.map { |group|
      "- #{group.email}"
    }.join("\n")
  end
end
empty_groups(gateway) click to toggle source
# File lib/lita/commands/empty_groups.rb, line 29
def empty_groups(gateway)
  gateway.groups.select { |group|
    group.member_count == 0
  }
end