Class: AlacrityRails::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/alacrity-rails/diagnostic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



3
# File 'lib/alacrity-rails/diagnostic.rb', line 3

def self.run; new.run end

Instance Method Details

#api_token_presentObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/alacrity-rails/diagnostic.rb', line 32

def api_token_present
  [
    Config.api_token.present?,
    %<
      The API token could not be found in the server environment.

      You can find it on https://alacrityapp.com then set it in your server config as `ALACRITY_API_TOKEN`.
    >
  ]
end

#loggerObject



5
# File 'lib/alacrity-rails/diagnostic.rb', line 5

def logger; @logger ||= Logger.new(STDOUT) end

#middleware_appears_firstObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/alacrity-rails/diagnostic.rb', line 66

def middleware_appears_first
  [
    Rails.application.config.middleware.first == (AlacrityRails::Middleware),
    %<
      The AlacrityRails::Middleware is not first in your middleware stack.
      Anything appearing above it will not be included in metrics tracking.

#{Rails.application.config.middleware.map(&:inspect).to_yaml}
    >
  ]
end

#middleware_presentObject



56
57
58
59
60
61
62
63
64
# File 'lib/alacrity-rails/diagnostic.rb', line 56

def middleware_present
  [
    Rails.application.config.middleware.include?(AlacrityRails::Middleware),
    %<
      The AlacrityRails::Middleware is absent from your middleware stack.
      Make sure your application is not overriding the middleware stack in an initializer.
    >
  ]
end

#runObject



7
8
9
10
11
12
13
14
15
# File 'lib/alacrity-rails/diagnostic.rb', line 7

def run
  run_check :api_token_present
  run_check :valid_api_token
  run_check :middleware_present
  run_check :middleware_appears_first

  puts success_message
  puts assistance_message
end

#run_check(check_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/alacrity-rails/diagnostic.rb', line 17

def run_check(check_name)
  logger << "CHECK: #{check_name.to_s.humanize}..."

  successful, display_message = public_send(check_name)

  if successful
    logger << "PASSED\n"
  else
    logger << "FAILED\n"
    logger << display_message
    logger << assistance_message
    exit
  end
end

#valid_api_tokenObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/alacrity-rails/diagnostic.rb', line 43

def valid_api_token
  response = Client.transmit(Transaction::ConnectionTest.new)

  [
    response.value.code == '200',
    %<
      Oh no! Its seems like we have a problem!

      #{JSON.parse(response.value.body)['message']}
    >
  ]
end