Class: Rookout::Interface

Inherits:
Object
  • Object
show all
Includes:
Exceptions, Singleton
Defined in:
lib/rookout/interface.rb

Instance Method Summary collapse

Constructor Details

#initializeInterface

Returns a new instance of Interface.



11
12
13
14
# File 'lib/rookout/interface.rb', line 11

def initialize
  @rook = nil
  @start_options = nil
end

Instance Method Details

#flushObject



55
56
57
# File 'lib/rookout/interface.rb', line 55

def flush
  @rook.flush unless @rook.nil?
end


16
17
18
19
# File 'lib/rookout/interface.rb', line 16

def print_debug_messages
  puts "[Rookout] Running in debug mode"
  puts "[Rookout] Rookout SDK for ruby: #{Config.rookout_version}"
end

#start(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rookout/interface.rb', line 21

def start options = {}
  return unless @rook.nil?
  throw_errors = options[:throw_errors] == true
  Config.debug = evaluate_flag options[:debug], "ROOKOUT_DEBUG"

  print_debug_messages if Config.debug

  begin
    verify_env

    require_relative "rookout_singleton"

    configure options

    rook = RookoutSingleton.instance
    @start_options[throw_errors: throw_errors]
    rook.connect(**@start_options)
  rescue LoadError
    raise if throw_errors
    $stderr.puts "[Rookout] Failed to load Rookout. Please make sure to force build native extensions by setting" \
                 "'bundle config force_ruby_platform true'"
  rescue RookMissingToken, RookInvalidToken, RookInvalidOptions,
         RookVersionNotSupported, RookBadProtobuf, RookWebSocketError => e
    raise if throw_errors
    $stderr.puts "[Rookout] Failed to start Rookout: #{e.message}"
  rescue RookCommunicationException => e
    raise if throw_errors
    Logger.instance.warning "[Rookout] #{e.message}"
  rescue Exception => e
    $stderr.puts e.full_message if Config.debug
    raise if throw_errors
  end
end

#stopObject



59
60
61
62
63
64
# File 'lib/rookout/interface.rb', line 59

def stop
  return if @rook.nil?

  @rook.stop
  @rook = nil
end