Class: Mbeditor::EditorChannel

Inherits:
CableBaseClass
  • Object
show all
Defined in:
app/channels/mbeditor/editor_channel.rb

Instance Method Summary collapse

Instance Method Details

#save_branch_state(data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'app/channels/mbeditor/editor_channel.rb', line 30

def save_branch_state(data)
  branch = data["branch"].to_s.strip
  state  = data["state"]
  EditorStateService.new(workspace_root).write_branch_state(branch, state)
rescue EditorStateService::InvalidBranchError
  # A misbehaving client sent a malformed branch name. Don't crash the
  # connection, but log it so the misconfiguration is observable.
  Rails.logger.warn("[mbeditor] EditorChannel#save_branch_state: rejected invalid branch name #{branch.inspect}")
rescue StandardError
  # Never let a state-save failure crash the WebSocket connection
end

#save_state(data) ⇒ Object



23
24
25
26
27
28
# File 'app/channels/mbeditor/editor_channel.rb', line 23

def save_state(data)
  state = data["state"] || data
  EditorStateService.new(workspace_root).write_state(state)
rescue StandardError
  # Never let a state-save failure crash the WebSocket connection
end

#start_log_tail(data) ⇒ Object



42
43
44
45
46
# File 'app/channels/mbeditor/editor_channel.rb', line 42

def start_log_tail(data)
  raw = data && data["offset"]
  @log_offset = raw.nil? ? nil : raw.to_i
  @log_watching = true
end

#stop_log_tail(_data = nil) ⇒ Object



48
49
50
# File 'app/channels/mbeditor/editor_channel.rb', line 48

def stop_log_tail(_data = nil)
  @log_watching = false
end

#subscribedObject



10
11
12
# File 'app/channels/mbeditor/editor_channel.rb', line 10

def subscribed
  stream_from "mbeditor_editor" if respond_to?(:stream_from)
end

#unsubscribedObject



19
20
21
# File 'app/channels/mbeditor/editor_channel.rb', line 19

def unsubscribed
  # no-op
end