Method: Whatup::CLI::Interactive#room

Defined in:
lib/whatup/cli/commands/interactive/interactive.rb

#room(name) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/whatup/cli/commands/interactive/interactive.rb', line 54

def room name
  if room = Room.find_by(name: name)
    current_user.puts <<~MSG
      Entering #{room.name}... enjoy your stay!

      Type `.exit` to exit this chat room.

      Currently in this room:
      #{room.clients.map do |client|
          "- #{client.name}\n"
        end.join}
    MSG
    current_user.update! room: room

    server.clients.reject { |c| c.id == current_user.id }.each do |c|
      c.puts <<~MSG
        #{current_user.name} has arrived! Play nice, kids.
      MSG
    end

    room.clients << current_user
    return
  end

  room = server.new_room! name: name, clients: [current_user]

  current_user.puts <<~MSG
    Created and entered #{room.name}... invite some people or something!

    Type `.exit` to exit this chat room.
  MSG
end