Class: LitmusPaper::StatusFile

Inherits:
Object
  • Object
show all
Defined in:
lib/litmus_paper/status_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, forced) ⇒ StatusFile

Returns a new instance of StatusFile.



40
41
42
43
# File 'lib/litmus_paper/status_file.rb', line 40

def initialize(filename, forced)
  @path = File.join(LitmusPaper.data_directory, filename)
  @forced = forced
end

Instance Attribute Details

#forcedObject (readonly)

Returns the value of attribute forced.



3
4
5
# File 'lib/litmus_paper/status_file.rb', line 3

def forced
  @forced
end

Class Method Details

.global_down_fileObject



5
6
7
# File 'lib/litmus_paper/status_file.rb', line 5

def self.global_down_file
  new("global_down", :down)
end

.global_health_fileObject



13
14
15
# File 'lib/litmus_paper/status_file.rb', line 13

def self.global_health_file
  new("global_health", :health)
end

.global_up_fileObject



9
10
11
# File 'lib/litmus_paper/status_file.rb', line 9

def self.global_up_file
  new("global_up", :up)
end

.priority_check_order_for_service(service_name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/litmus_paper/status_file.rb', line 29

def self.priority_check_order_for_service(service_name)
  [
    global_down_file,
    global_up_file,
    global_health_file,
    service_down_file(service_name),
    service_up_file(service_name),
    service_health_file(service_name),
  ]
end

.service_down_file(service_name) ⇒ Object



17
18
19
# File 'lib/litmus_paper/status_file.rb', line 17

def self.service_down_file(service_name)
  new("#{service_name}_down", :down)
end

.service_health_file(service_name) ⇒ Object



25
26
27
# File 'lib/litmus_paper/status_file.rb', line 25

def self.service_health_file(service_name)
  new("#{service_name}_health", :health)
end

.service_up_file(service_name) ⇒ Object



21
22
23
# File 'lib/litmus_paper/status_file.rb', line 21

def self.service_up_file(service_name)
  new("#{service_name}_up", :up)
end

Instance Method Details

#contentObject



45
46
47
# File 'lib/litmus_paper/status_file.rb', line 45

def content
  File.read(@path).chomp
end

#create(reason, health = nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/litmus_paper/status_file.rb', line 49

def create(reason, health = nil)
  FileUtils.mkdir_p(File.dirname(@path))
  File.open(@path, 'w') do |file|
    file.puts(reason)
    file.puts(health) if health
  end
end

#deleteObject



57
58
59
# File 'lib/litmus_paper/status_file.rb', line 57

def delete
  FileUtils.rm(@path)
end

#exists?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/litmus_paper/status_file.rb', line 61

def exists?
  File.exists?(@path)
end