Class: Flutter::Persistence::Yaml
- Inherits:
-
AbstractStorage
- Object
- AbstractStorage
- Flutter::Persistence::Yaml
- Defined in:
- lib/flutter/persistence.rb
Constant Summary collapse
- YAML_LOAD_OPTS =
ruby >= 3.1 requires this
RUBY_VERSION > "3.1" ? { permitted_classes: [Hash, Set, Symbol] } : {}
Instance Method Summary collapse
-
#clear! ⇒ void
Clear any saved state in the underlying storage.
-
#initialize(path:) ⇒ Yaml
constructor
A new instance of Yaml.
-
#load! ⇒ void
If the storage was already persisted load the current state.
-
#persist! ⇒ void
Save the state of test & source mapping to the underlying storage.
-
#source_mapping ⇒ Hash<String, Hash<String, String>>
Mapping of +source file -> callable_id -> signature+.
-
#test_mapping ⇒ Hash<String, Hash<String, Set<String>>>
Mapping of +test_id -> source file -> callable_id+.
- #to_s ⇒ Object
-
#update_source_mapping!(mapping) ⇒ Object
Update #source_mapping.
-
#update_test_mapping!(mapping) ⇒ Object
Update #test_mapping.
Constructor Details
#initialize(path:) ⇒ Yaml
Returns a new instance of Yaml.
81 82 83 84 85 86 |
# File 'lib/flutter/persistence.rb', line 81 def initialize(path:) @path = File.absolute_path(path) @full_path = File.join(@path, "state.yml") @state = { test_mapping: {}, source_mapping: {} } super() end |
Instance Method Details
#clear! ⇒ void
This method returns an undefined value.
Clear any saved state in the underlying storage
117 118 119 120 |
# File 'lib/flutter/persistence.rb', line 117 def clear! FileUtils.rm(@full_path) if File.exist?(@full_path) @state.clear end |
#load! ⇒ void
This method returns an undefined value.
If the storage was already persisted load the current state
89 90 91 92 93 94 |
# File 'lib/flutter/persistence.rb', line 89 def load! if File.exist?(@full_path) persisted = YAML.load(File.read(@full_path), **YAML_LOAD_OPTS) @state.update(persisted) if persisted end end |
#persist! ⇒ void
This method returns an undefined value.
Save the state of test & source mapping to the underlying storage
123 124 125 126 |
# File 'lib/flutter/persistence.rb', line 123 def persist! FileUtils.mkdir_p(@path) unless File.exist?(@path) File.open(@full_path, "w") { |file| file.write(@state.to_yaml) } end |
#source_mapping ⇒ Hash<String, Hash<String, String>>
Mapping of +source file -> callable_id -> signature+
102 103 104 |
# File 'lib/flutter/persistence.rb', line 102 def source_mapping @state.fetch(:source_mapping) { @state[:source_mapping] = {} } end |
#test_mapping ⇒ Hash<String, Hash<String, Set<String>>>
Mapping of +test_id -> source file -> callable_id+
97 98 99 |
# File 'lib/flutter/persistence.rb', line 97 def test_mapping @state.fetch(:test_mapping) { @state[:test_mapping] = {} } end |
#to_s ⇒ Object
128 129 130 |
# File 'lib/flutter/persistence.rb', line 128 def to_s "state: #{@full_path}" end |
#update_source_mapping!(mapping) ⇒ Object
Update #source_mapping
112 113 114 |
# File 'lib/flutter/persistence.rb', line 112 def update_source_mapping!(mapping) source_mapping.merge!(mapping) end |
#update_test_mapping!(mapping) ⇒ Object
Update #test_mapping
107 108 109 |
# File 'lib/flutter/persistence.rb', line 107 def update_test_mapping!(mapping) test_mapping.merge!(mapping) end |