class Lita::Commands::NoOrgUnit

Public Instance Methods

name() click to toggle source
# File lib/lita/commands/no_org_unit.rb, line 5
def name
  'no-org-unit'
end
run(robot, target, gateway, opts = {}) click to toggle source
# File lib/lita/commands/no_org_unit.rb, line 9
def run(robot, target, gateway, opts = {})
  msg = build_msg(gateway)
  robot.send_message(target, msg) if msg
  robot.send_message(target, "No users are missing an org unit") if msg.nil? && opts[:negative_ack]
end

Private Instance Methods

build_msg(gateway) click to toggle source
# File lib/lita/commands/no_org_unit.rb, line 17
def build_msg(gateway)
  users = no_org_unit_users(gateway)

  if users.any?
    msg = "The following users are not assigned to an organisational unit:\n"
    msg += users.sort_by(&:path).map { |user|
      "- #{user.email}"
    }.join("\n")
  end
end
no_org_unit_users(gateway) click to toggle source
# File lib/lita/commands/no_org_unit.rb, line 28
def no_org_unit_users(gateway)
  gateway.users.reject { |user|
    user.suspended?
  }.select { |user|
    user.ou_path == "/"
  }
end