Class: AnyCable::Socket::State
- Inherits:
-
Object
- Object
- AnyCable::Socket::State
- Defined in:
- lib/anycable/socket.rb
Overview
Represents the per-connection store (for example, used to keep session beetween RPC calls)
Instance Attribute Summary collapse
-
#dirty_keys ⇒ Object
readonly
Returns the value of attribute dirty_keys.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #changed_fields ⇒ Object
-
#initialize(from) ⇒ State
constructor
A new instance of State.
- #read(key) ⇒ Object (also: #[])
- #write(key, val) ⇒ Object (also: #[]=)
Constructor Details
#initialize(from) ⇒ State
Returns a new instance of State.
16 17 18 19 |
# File 'lib/anycable/socket.rb', line 16 def initialize(from) @source = from @dirty_keys = nil end |
Instance Attribute Details
#dirty_keys ⇒ Object (readonly)
Returns the value of attribute dirty_keys.
14 15 16 |
# File 'lib/anycable/socket.rb', line 14 def dirty_keys @dirty_keys end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
14 15 16 |
# File 'lib/anycable/socket.rb', line 14 def source @source end |
Instance Method Details
#changed_fields ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/anycable/socket.rb', line 40 def changed_fields return unless source keys = dirty_keys return if keys.nil? source.slice(*keys) end |
#read(key) ⇒ Object Also known as: []
21 22 23 |
# File 'lib/anycable/socket.rb', line 21 def read(key) source&.[](key) end |
#write(key, val) ⇒ Object Also known as: []=
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/anycable/socket.rb', line 27 def write(key, val) return if source&.[](key) == val @source ||= {} keys = (@dirty_keys ||= []) keys << key source[key] = val end |