Class: ApplicationCable::State
- Inherits:
-
Object
- Object
- ApplicationCable::State
show all
- Defined in:
- lib/activestate/channel.rb
Instance Method Summary
collapse
Constructor Details
#initialize(subject, channel, path = nil) ⇒ State
Returns a new instance of State.
3
4
5
6
7
|
# File 'lib/activestate/channel.rb', line 3
def initialize subject, channel, path = nil
@channel = channel
@subject = subject
@path = path
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, data) ⇒ Object
35
36
37
|
# File 'lib/activestate/channel.rb', line 35
def method_missing method, data
transmit method, data
end
|
Instance Method Details
#assign(value) ⇒ Object
23
24
25
|
# File 'lib/activestate/channel.rb', line 23
def assign value
transmit :assign, value
end
|
#delete(value) ⇒ Object
31
32
33
|
# File 'lib/activestate/channel.rb', line 31
def delete value
transmit :delete, value
end
|
#set(value) ⇒ Object
19
20
21
|
# File 'lib/activestate/channel.rb', line 19
def set value
transmit :set, value
end
|
#transmit(action, data) ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/activestate/channel.rb', line 10
def transmit action, data
message = {path: @path, action: action}.compact
if @subject
@channel.broadcast_to @subject, message.merge(data: data)
else
@channel.transmit message.merge(data: data)
end
end
|
#upsert(value, key = 'id') ⇒ Object
27
28
29
|
# File 'lib/activestate/channel.rb', line 27
def upsert value, key = 'id'
transmit :upsert, key: key, value: value
end
|