Class: Synack::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/synack/server.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  host: 'localhost',
  port: 11113
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



13
14
15
# File 'lib/synack/server.rb', line 13

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



13
14
15
# File 'lib/synack/server.rb', line 13

def port
  @port
end

#socketObject (readonly)

Returns the value of attribute socket.



13
14
15
# File 'lib/synack/server.rb', line 13

def socket
  @socket
end

Class Method Details

.start(options = {}) ⇒ Object

Class methods ================================================================================



17
18
19
20
21
22
23
24
25
# File 'lib/synack/server.rb', line 17

def self.start(options={})
  options = DEFAULT_OPTIONS.merge(options)
  @host = options[:host]
  @port = options[:port].to_i
  @@server = Synack::Server.new
  puts "Synack server running. Fire at will."
  ::DRb.start_service("druby://#{@host}:#{@port}", @@server)
  ::DRb.thread.join
end

.stopObject



27
28
29
# File 'lib/synack/server.rb', line 27

def self.stop
  ::DRb.stop_service
end

Instance Method Details

#sanitize(message) ⇒ Object

Instance methods =============================================================================



33
34
35
# File 'lib/synack/server.rb', line 33

def sanitize(message)
  message && message.gsub(/[^0-9A-z\.\-\'\, ]/, '_')
end

#say(message) ⇒ Object



37
38
39
40
# File 'lib/synack/server.rb', line 37

def say(message)
  puts message
  system "/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -message \"#{sanitize(message)}\""
end