Class: Reyes::RunGeneration
- Inherits:
-
Object
- Object
- Reyes::RunGeneration
- 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
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#increment! ⇒ Integer
Increment the generation value and save it to disk.
-
#initialize(path = DefaultGenerationPath) ⇒ RunGeneration
constructor
If the file at ‘path` does not exist, it will be created.
-
#set!(value) ⇒ Object
Set the generation value and save it to disk.
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.
19 20 21 22 |
# File 'lib/reyes/run_generation.rb', line 19 def initialize(path=DefaultGenerationPath) @path = path reload end |
Instance Attribute Details
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
11 12 13 |
# File 'lib/reyes/run_generation.rb', line 11 def mtime @mtime end |
#value ⇒ Object (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.
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.
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 |