class NewlineHw::StreamCommandHandler
A json message handler to trigger actions from chrome native messaging
Constants
- EVENTS
Attributes
data[R]
event[R]
message_at[R]
Public Class Methods
new(event)
click to toggle source
# File lib/newline_hw/stream_command_handler.rb, line 14 def initialize(event) @event = event["event"].to_sym @data = event["data"] @message_at = event["message_at"].to_i end
Public Instance Methods
call()
click to toggle source
# File lib/newline_hw/stream_command_handler.rb, line 24 def call return handle_unknown unless known_event? send(event) rescue StandardError => e handle_fail(e) end
check_if_cloneable()
click to toggle source
# File lib/newline_hw/stream_command_handler.rb, line 46 def check_if_cloneable setup = Shell::Setup.new(data["id"], Config.new) { status: :ok, message_at: message_at, data: { cloneable: setup.cloneable?, submission_info: setup.submission_info } } end
clone_and_open_submission()
click to toggle source
# File lib/newline_hw/stream_command_handler.rb, line 58 def clone_and_open_submission { status: :ok, message_at: message_at, data: GuiTrigger.new(data, Config.new).call } end
handle_fail(e)
click to toggle source
# File lib/newline_hw/stream_command_handler.rb, line 75 def handle_fail(e) { status: :fail, event: @event, message_at: message_at, message: e.message } end
handle_unknown()
click to toggle source
# File lib/newline_hw/stream_command_handler.rb, line 66 def handle_unknown { status: :fail, message_at: message_at, message: \ "no event handler found in Stream Command Handler for #{@event}" } end
heartbeat()
click to toggle source
# File lib/newline_hw/stream_command_handler.rb, line 32 def heartbeat { status: :ok, message_at: message_at, data: { newline_hw_version: NewlineHw::VERSION, ruby_version: RUBY_VERSION, newline_hw_config_path: Config::CONFIG_PATH, newline_hw_path: NewlineHw.root_path, newline_hw_config: Config.new.config } } end
known_event?()
click to toggle source
# File lib/newline_hw/stream_command_handler.rb, line 20 def known_event? EVENTS.include?(event) end