Class: Rack::Downtime::Strategy::File

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/downtime/strategy.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ File

Returns a new instance of File.



87
88
89
90
# File 'lib/rack/downtime/strategy.rb', line 87

def initialize(path = nil)
  @path  = path || self.class.path
  @mtime = 0
end

Class Attribute Details

.pathObject



82
83
84
# File 'lib/rack/downtime/strategy.rb', line 82

def path
  @path ||= "downtime.txt"
end

Instance Method Details

#call(env) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rack/downtime/strategy.rb', line 92

def call(env)
  return unless ::File.exists?(@path)

  new_mtime = ::File.mtime(@path).to_i
  if new_mtime > @mtime
    @downtime = parse_downtime(@path)
    @mtime = new_mtime
  end

  @downtime
end