Class: Flutter::Persistence::Marshal

Inherits:
AbstractStorage show all
Defined in:
lib/flutter/persistence.rb

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Marshal

Returns a new instance of Marshal.

Parameters:

  • path (String)

    The directory to store the marshaled state file +state.pstore+



150
151
152
153
154
155
156
# File 'lib/flutter/persistence.rb', line 150

def initialize(path:)
  @path = File.absolute_path(path)
  FileUtils.mkdir_p(@path) unless File.exist?(@path)
  @full_path = File.join(@path, "state.pstore")
  @state = nil
  super()
end

Instance Method Details

#clear!void

This method returns an undefined value.

Clear any saved state in the underlying storage



207
208
209
# File 'lib/flutter/persistence.rb', line 207

def clear!
  FileUtils.rm(@full_path) if File.exist?(@full_path)
end

#load!void

This method returns an undefined value.

If the storage was already persisted load the current state



159
160
161
162
163
164
165
# File 'lib/flutter/persistence.rb', line 159

def load!
  @state = PStore.new(@full_path)
  @state.transaction do
    @state[:test_mapping] ||= {}
    @state[:source_mapping] ||= {}
  end
end

#persist!void

This method returns an undefined value.

Save the state of test & source mapping to the underlying storage



212
213
# File 'lib/flutter/persistence.rb', line 212

def persist!
end

#source_hintsHash<String, Set<String>]

Mapping of +source file -> class or module

Returns:

  • (Hash<String, Set<String>])

    Hash]



182
183
184
185
186
# File 'lib/flutter/persistence.rb', line 182

def source_hints
  @state.transaction do
    return @state[:source_hints] || {}
  end
end

#source_mappingHash<String, Hash<String, String>>

Mapping of +source file -> callable_id -> signature+

Returns:

  • (Hash<String, Hash<String, String>>)


175
176
177
178
179
# File 'lib/flutter/persistence.rb', line 175

def source_mapping
  @state.transaction do
    return @state[:source_mapping] || {}
  end
end

#test_mappingHash<String, Hash<String, Set<String>>>

Mapping of +test_id -> source file -> callable_id+

Returns:

  • (Hash<String, Hash<String, Set<String>>>)


168
169
170
171
172
# File 'lib/flutter/persistence.rb', line 168

def test_mapping
  @state.transaction do
    return @state[:test_mapping] || {}
  end
end

#to_sString

Returns:

  • (String)


216
217
218
# File 'lib/flutter/persistence.rb', line 216

def to_s
  "state: #{@full_path}"
end

#update_source_mapping!(mapping, hints) ⇒ Object

Parameters:

  • mapping (Hash<String, Hash<String, String>>)
  • hints (Hash<String, Hash<String, String>>)


197
198
199
200
201
202
203
204
# File 'lib/flutter/persistence.rb', line 197

def update_source_mapping!(mapping, hints)
  @state.transaction do
    @state[:source_mapping] ||= {}
    @state[:source_hints] ||= {}
    @state[:source_mapping].deep_merge!(mapping)
    @state[:source_hints].deep_merge!(hints)
  end
end

#update_test_mapping!(mapping) ⇒ Object

Update #test_mapping

Parameters:

  • mapping (Hash<String, Hash<String, String>>)


189
190
191
192
193
194
# File 'lib/flutter/persistence.rb', line 189

def update_test_mapping!(mapping)
  @state.transaction do
    @state[:test_mapping] ||= {}
    @state[:test_mapping].merge!(mapping)
  end
end