Class: Navo::SuiteState
- Inherits:
-
Object
- Object
- Navo::SuiteState
- Defined in:
- lib/navo/suite_state.rb
Overview
Stores persisted state about a test suite.
This allows information to carry forward between different invocations of the tool, e.g. remembering a previously-started Docker container.
Constant Summary collapse
- FILE_NAME =
'state.yaml'
Instance Method Summary collapse
-
#[](key) ⇒ Array, ...
Access the state as if it were a hash.
-
#[]=(key, value) ⇒ Object
Set the state as if it were a hash.
-
#destroy ⇒ Object
Destroy persisted state.
-
#initialize(suite:) ⇒ SuiteState
constructor
A new instance of SuiteState.
-
#load ⇒ Object
Loads persisted state.
-
#save ⇒ Object
Persists state to disk.
Constructor Details
#initialize(suite:) ⇒ SuiteState
Returns a new instance of SuiteState.
12 13 14 |
# File 'lib/navo/suite_state.rb', line 12 def initialize(suite:) @suite = suite end |
Instance Method Details
#[](key) ⇒ Array, ...
Access the state as if it were a hash.
20 21 22 |
# File 'lib/navo/suite_state.rb', line 20 def [](key) @hash[key.to_s] end |
#[]=(key, value) ⇒ Object
Set the state as if it were a hash.
28 29 30 |
# File 'lib/navo/suite_state.rb', line 28 def []=(key, value) @hash[key.to_s] = value end |
#destroy ⇒ Object
Destroy persisted state.
48 49 50 51 |
# File 'lib/navo/suite_state.rb', line 48 def destroy @hash = {} FileUtils.rm_f(file_path) end |
#load ⇒ Object
Loads persisted state.
33 34 35 36 37 38 39 40 |
# File 'lib/navo/suite_state.rb', line 33 def load @hash = if File.exist?(file_path) && yaml = YAML.load_file(file_path) yaml.to_hash else {} # Handle empty files end end |
#save ⇒ Object
Persists state to disk.
43 44 45 |
# File 'lib/navo/suite_state.rb', line 43 def save File.open(file_path, 'w') { |f| f.write(@hash.to_yaml) } end |