class Spurious::Command::State

Attributes

app[RW]
type[R]

Public Class Methods

new(type, app, *args) click to toggle source
Calls superclass method
# File lib/spurious/command/state.rb, line 13
def initialize(type, app, *args)
  super
  @type = type
  @app = app
  @exiting = false
end

Public Instance Methods

close_connection() click to toggle source
# File lib/spurious/command/state.rb, line 42
def close_connection
  @exiting = true
  EventMachine.stop_event_loop
  exit
end
post_init() click to toggle source
# File lib/spurious/command/state.rb, line 27
def post_init
  send_data JSON.generate(:type => type)
end
receive_data(data) click to toggle source
# File lib/spurious/command/state.rb, line 31
def receive_data(data)
  data_parts = data.split("\n")
  data_parts.each do |data_part|
    parsed_data = JSON.parse(data_part.strip)
    output parsed_data
    if parsed_data['close']
      close_connection
    end
  end
end
unbind() click to toggle source
# File lib/spurious/command/state.rb, line 20
def unbind
  unless @exiting
    app.say "[error] The spurious-server instance has died, start it again with: 'spurious-server start'", :red
    EventMachine.stop_event_loop
  end
end

Protected Instance Methods

output(data) click to toggle source
# File lib/spurious/command/state.rb, line 50
def output(data)
  message_type = data['message_type']
  if message_type != 'debug' || (message_type == 'debug' && app.options['debug_mode'] == 'true')
    app.say "[#{data['message_type']}] #{data['response']}", data['colour'].to_sym
  end
end