Class: CableRoom::Room::PortManagement::PortClient
- Inherits:
-
Object
- Object
- CableRoom::Room::PortManagement::PortClient
- Defined in:
- lib/cable_room/room/port_management.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#initialize(room, token) ⇒ PortClient
constructor
A new instance of PortClient.
- #merge!(value) ⇒ Object
- #recently_seen? ⇒ Boolean
- #tag!(*tags) ⇒ Object
- #tagged?(tag) ⇒ Boolean
- #touch_activity! ⇒ Object
Constructor Details
#initialize(room, token) ⇒ PortClient
Returns a new instance of PortClient.
165 166 167 168 169 170 171 |
# File 'lib/cable_room/room/port_management.rb', line 165 def initialize(room, token) @room = room @token = token @metadata = HashWithIndifferentAccess.new @metadata[:tags] = Set.new touch_activity! end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
163 164 165 |
# File 'lib/cable_room/room/port_management.rb', line 163 def token @token end |
Instance Method Details
#<<(data) ⇒ Object
175 176 177 178 179 |
# File 'lib/cable_room/room/port_management.rb', line 175 def <<(data) @room.with_port_scope(client_port: @token) do @room.broadcast(data) end end |
#merge!(value) ⇒ Object
181 182 183 |
# File 'lib/cable_room/room/port_management.rb', line 181 def merge!(value) @metadata.merge!(value || {}) end |
#recently_seen? ⇒ Boolean
189 190 191 |
# File 'lib/cable_room/room/port_management.rb', line 189 def recently_seen? self[:last_seen_at] && self[:last_seen_at] > PORT_TIMEOUT.ago end |
#tag!(*tags) ⇒ Object
197 198 199 |
# File 'lib/cable_room/room/port_management.rb', line 197 def tag!(*) self[:tags].merge(.flatten.map(&:to_sym)) end |
#tagged?(tag) ⇒ Boolean
193 194 195 |
# File 'lib/cable_room/room/port_management.rb', line 193 def tagged?(tag) self[:tags].include?(tag) end |
#touch_activity! ⇒ Object
185 186 187 |
# File 'lib/cable_room/room/port_management.rb', line 185 def touch_activity! self[:last_seen_at] = Time.now end |