Class: Wellness::System

Inherits:
Object
  • Object
show all
Defined in:
lib/wellness/system.rb

Overview

Author:

  • Matthew A. Johnston (warmwaffles)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ System

Returns a new instance of System.

Parameters:

  • name (String)

    the name of the system



10
11
12
13
14
15
# File 'lib/wellness/system.rb', line 10

def initialize(name)
  @name = name
  @services = []
  @details = []
  @mutex = Mutex.new
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/wellness/system.rb', line 7

def name
  @name
end

Instance Method Details

#build_reportObject



38
39
40
41
42
# File 'lib/wellness/system.rb', line 38

def build_report
  @mutex.synchronize do
    Wellness::Report.new(services.map(&:call), details.map(&:call))
  end
end

#detailed_checkObject



28
29
30
31
# File 'lib/wellness/system.rb', line 28

def detailed_check
  report = build_report
  [report.status_code, { 'Content-Type' => 'application/json' }, [report.detailed.to_json]]
end

#detailsObject



48
49
50
# File 'lib/wellness/system.rb', line 48

def details
  @details.map(&:build)
end

#servicesObject



44
45
46
# File 'lib/wellness/system.rb', line 44

def services
  @services.map(&:build)
end

#simple_checkObject



33
34
35
36
# File 'lib/wellness/system.rb', line 33

def simple_check
  report = build_report
  [report.status_code, { 'Content-Type' => 'application/json' }, [report.simple.to_json]]
end

#use(klass, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/wellness/system.rb', line 17

def use(klass, *args)
  @mutex.synchronize do
    factory = Factory.new(klass, *args)
    if klass <= Wellness::Services::Base
      @services << factory
    else
      @details << factory
    end
  end
end