Class: Reyes::RunGeneration

Inherits:
Object
  • Object
show all
Includes:
Chalk::Log
Defined in:
lib/reyes/run_generation.rb

Overview

An abstraction over tmpfile based generation number storage.

Defined Under Namespace

Classes: LoadError

Constant Summary collapse

DefaultGenerationPath =
"/tmp/reyes.u#{Process.euid}.generation"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = DefaultGenerationPath) ⇒ RunGeneration

If the file at ‘path` does not exist, it will be created. Attempting to open a symbolic link will raise Errno::ELOOP to avoid security vulnerabilities.

Parameters:

  • path (String) (defaults to: DefaultGenerationPath)

    Path to generation file



19
20
21
22
# File 'lib/reyes/run_generation.rb', line 19

def initialize(path=DefaultGenerationPath)
  @path = path
  reload
end

Instance Attribute Details

#mtimeObject (readonly)

Returns the value of attribute mtime.



11
12
13
# File 'lib/reyes/run_generation.rb', line 11

def mtime
  @mtime
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/reyes/run_generation.rb', line 10

def value
  @value
end

Instance Method Details

#increment!Integer

Increment the generation value and save it to disk.

Returns:

  • (Integer)

    new generation value



28
29
30
31
32
33
# File 'lib/reyes/run_generation.rb', line 28

def increment!
  @value += 1
  log.debug("Incrementing generation to #{@value}")
  save
  @value
end

#set!(value) ⇒ Object

Set the generation value and save it to disk.

Parameters:

  • value (Integer)


39
40
41
42
43
44
45
46
47
# File 'lib/reyes/run_generation.rb', line 39

def set!(value)
  unless value.is_a?(Integer)
    raise ArgumentError.new("Not an integer: #{value.inspect}")
  end
  @value = value
  log.debug("Setting generation to #{@value}")
  save(true)
  @value
end