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_hints ⇒ Hash<String, Set<String>]
Mapping of +source file -> class or module.
-
#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, hints) ⇒ Object
Update #source_mapping.
-
#update_test_mapping!(mapping) ⇒ Object
Update #test_mapping.
Constructor Details
#initialize(path:) ⇒ Yaml
Returns a new instance of Yaml.
89 90 91 92 93 94 |
# File 'lib/flutter/persistence.rb', line 89 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
131 132 133 134 |
# File 'lib/flutter/persistence.rb', line 131 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
97 98 99 100 101 102 |
# File 'lib/flutter/persistence.rb', line 97 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
137 138 139 140 |
# File 'lib/flutter/persistence.rb', line 137 def persist! FileUtils.mkdir_p(@path) unless File.exist?(@path) File.open(@full_path, "w") { |file| file.write(@state.to_yaml) } end |
#source_hints ⇒ Hash<String, Set<String>]
Mapping of +source file -> class or module
115 116 117 |
# File 'lib/flutter/persistence.rb', line 115 def source_hints @state.fetch(:source_hints) { @state[:source_hints] = {} } end |
#source_mapping ⇒ Hash<String, Hash<String, String>>
Mapping of +source file -> callable_id -> signature+
110 111 112 |
# File 'lib/flutter/persistence.rb', line 110 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+
105 106 107 |
# File 'lib/flutter/persistence.rb', line 105 def test_mapping @state.fetch(:test_mapping) { @state[:test_mapping] = {} } end |
#to_s ⇒ Object
142 143 144 |
# File 'lib/flutter/persistence.rb', line 142 def to_s "state: #{@full_path}" end |
#update_source_mapping!(mapping, hints) ⇒ Object
Update #source_mapping
125 126 127 128 |
# File 'lib/flutter/persistence.rb', line 125 def update_source_mapping!(mapping, hints) source_mapping.deep_merge!(mapping) source_hints.deep_merge!(hints) end |
#update_test_mapping!(mapping) ⇒ Object
Update #test_mapping
120 121 122 |
# File 'lib/flutter/persistence.rb', line 120 def update_test_mapping!(mapping) test_mapping.merge!(mapping) end |