class Nginxtra::Status

The status class encapsulates current state of nginxtra, such as when the last time nginx was compiled and with what options.

Constants

FILENAME

The name of the file that stores the state.

Attributes

status[RW]

Public Class Methods

[](option) click to toggle source

Retrieve an option from the state stored in the filesystem. This will first load the state from the .nginxtra_status file in the root of the nginxtra gem directory, if it has not yet been loaded.

# File lib/nginxtra/status.rb, line 18
def[](option)
  load!
  status[option]
end
[]=(option, value) click to toggle source

Store an option to the status state. This will save out to the filesystem immediately after storing this option. The return value will be the value stored to the given option key.

# File lib/nginxtra/status.rb, line 26
def[]=(option, value)
  load!
  status[option] = value
  save!
  value
end

Private Class Methods

load!() click to toggle source

Load the status state, if it hasn't yet been loaded. If there is no file yet existing, then the state is simply initialized to an empty hash (and it is NOT stored to the filesystem til the first write).

# File lib/nginxtra/status.rb, line 39
def load!
  return if status

  self.status = if File.exist? path
                  YAML.load File.read(path)
                else
                  {}
                end
end
path() click to toggle source

The full path to the file with the state.

# File lib/nginxtra/status.rb, line 50
def path
  File.join Nginxtra::Config.base_dir, FILENAME
end
save!() click to toggle source

Save the current state to disk.

# File lib/nginxtra/status.rb, line 55
def save!
  File.open path, "w" do |file|
    file << YAML.dump(status)
  end
end