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: 1ee10c77cdfcc15570f256077d60c6de08b5422dfae92a4b59428048392e31b4
4
- data.tar.gz: a2120cb662058bbbb724317970ac96a4d0c9803111f07f5f170df76e80fc0c22
3
+ metadata.gz: dbd1228a1c53e72f20c032f99bc292372d09f7729dadebf94c6c34afbb05c964
4
+ data.tar.gz: 60abdb1724b159d9935cbd7fafde1eb11d4a40ba43e097ffea02d8197c152032
5
5
  SHA512:
6
- metadata.gz: 4db17ea037a2c494a7461d9676f56854b69688f57229fe076e0df48f0d51a66f3cad3a9802fc1804b516cb021a662cdb51c81c3ea78144bd5f341d006914ef78
7
- data.tar.gz: e8bb59b0c2c77b86d37fd4d0908e0c44f08da41969df1525bdf1ea3da370595ec7ee9e4440ec5b7d048dd134e0f4f8448edee0247dcec26b7bca53e21b8938e4
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
- room.broadcast except: current_user do
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
@@ -46,7 +46,6 @@ module Whatup
46
46
  end
47
47
 
48
48
  def leave_room!
49
- broadcast 'LEFT'
50
49
  room.drop_client! self
51
50
  end
52
51
 
@@ -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
@@ -159,16 +159,18 @@ module Whatup
159
159
  def handle_chatting client
160
160
  loop do
161
161
  input = client.input!
162
- room = client.room
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
- room.broadcast except: client do
170
- "#{client.name}> #{input}"
171
- end
173
+ audience.each { |c| c.puts "#{client.name}> #{input}" }
172
174
  end
173
175
  end
174
176
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whatup
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  end
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.2
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 00:00:00.000000000 Z
11
+ date: 2019-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry