Class: StatusCacher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_path) ⇒ StatusCacher

Returns a new instance of StatusCacher.



4
5
6
7
8
9
# File 'lib/status_cacher.rb', line 4

def initialize(status_path)
  raise ArgumentError("No status path specified") if status_path.nil?
  @status_path = status_path

  FileUtils.touch(status_path)
end

Instance Attribute Details

#status_pathObject

Returns the value of attribute status_path.



2
3
4
# File 'lib/status_cacher.rb', line 2

def status_path
  @status_path
end

Instance Method Details

#statusObject



19
20
21
22
23
24
# File 'lib/status_cacher.rb', line 19

def status
  f = File.open(@status_path, "r")
  f.read
rescue StandardError => e
  raise StatusStorageError.new("Status path does not exist when it should #{@status_path}: #{e.inspect}")
end

#status=(value) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/status_cacher.rb', line 11

def status=(value)
  File.open(@status_path, 'w') { |f|
    f.write value
  }
rescue StandardError => e
  raise StatusStorageError.new("Could not write to status cache at #{@status_path}: #{e.inspect}")
end