whatup 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbd1228a1c53e72f20c032f99bc292372d09f7729dadebf94c6c34afbb05c964
|
4
|
+
data.tar.gz: 60abdb1724b159d9935cbd7fafde1eb11d4a40ba43e097ffea02d8197c152032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba017ae1a1f88dfb073371dfc8232d9761f5f03eb25fb1a4787b3c01ab1a176946bd65f613cb0b9c705e2ad5625fab509645639e23e4ba3770ef784fb02fa31
|
7
|
+
data.tar.gz: 98e9464facabb23102ce667ef2e089585b77d399d8a1f5dfc40a2e81a28cfc7aeed65211ae1f86ea27bcf9cf7b762fba8e0372cac5ac6f35b7255515b8b02ed1
|
@@ -51,7 +51,7 @@ module Whatup
|
|
51
51
|
end
|
52
52
|
|
53
53
|
desc 'room [NAME]', 'Create and enter chatroom [NAME]'
|
54
|
-
def room name
|
54
|
+
def room name # rubocop:disable Metrics/AbcSize
|
55
55
|
if room = Room.find_by(name: name)
|
56
56
|
current_user.puts <<~MSG
|
57
57
|
Entering #{room.name}... enjoy your stay!
|
@@ -65,8 +65,8 @@ module Whatup
|
|
65
65
|
MSG
|
66
66
|
current_user.update! room: room
|
67
67
|
|
68
|
-
|
69
|
-
<<~MSG
|
68
|
+
server.clients.reject { |c| c.id == current_user.id }.each do |c|
|
69
|
+
c.puts <<~MSG
|
70
70
|
#{current_user.name} has arrived! Play nice, kids.
|
71
71
|
MSG
|
72
72
|
end
|
@@ -5,21 +5,13 @@ require 'whatup/server/models/application_record'
|
|
5
5
|
module Whatup
|
6
6
|
module Server
|
7
7
|
class Room < ApplicationRecord
|
8
|
-
has_many :clients
|
8
|
+
has_many :clients, foreign_key: 'room_id'
|
9
9
|
|
10
10
|
validates :name, uniqueness: true
|
11
11
|
|
12
12
|
def drop_client! client
|
13
13
|
client.update! room_id: nil
|
14
14
|
end
|
15
|
-
|
16
|
-
def broadcast except: nil
|
17
|
-
if except
|
18
|
-
clients.where.not id: except.id
|
19
|
-
else
|
20
|
-
clients
|
21
|
-
end.each { |c| c&.puts(yield) }
|
22
|
-
end
|
23
15
|
end
|
24
16
|
end
|
25
17
|
end
|
data/lib/whatup/server/server.rb
CHANGED
@@ -159,16 +159,18 @@ module Whatup
|
|
159
159
|
def handle_chatting client
|
160
160
|
loop do
|
161
161
|
input = client.input!
|
162
|
-
|
162
|
+
audience = @clients.reject { |c| c.id == client.id }
|
163
|
+
.select do |c|
|
164
|
+
client.room.clients.pluck(:id).include? c.id
|
165
|
+
end
|
163
166
|
puts "#{client.name}> #{input}"
|
164
167
|
if input == '.exit'
|
168
|
+
client.puts "Exited `#{client.room.name}`."
|
169
|
+
audience.each { |c| c.puts "#{client.name}> LEFT" }
|
165
170
|
client.leave_room!
|
166
|
-
client.puts "Exited `#{room.name}`."
|
167
171
|
break
|
168
172
|
end
|
169
|
-
|
170
|
-
"#{client.name}> #{input}"
|
171
|
-
end
|
173
|
+
audience.each { |c| c.puts "#{client.name}> #{input}" }
|
172
174
|
end
|
173
175
|
end
|
174
176
|
|
data/lib/whatup/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whatup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Delk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|