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+



136
137
138
139
140
141
142
# File 'lib/flutter/persistence.rb', line 136

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



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

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



145
146
147
148
149
150
151
# File 'lib/flutter/persistence.rb', line 145

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



189
190
# File 'lib/flutter/persistence.rb', line 189

def persist!
end

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

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

Returns:

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

    mapping



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

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>>>)


154
155
156
157
158
# File 'lib/flutter/persistence.rb', line 154

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

#to_sString

Returns:

  • (String)


193
194
195
# File 'lib/flutter/persistence.rb', line 193

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

#update_source_mapping!(mapping) ⇒ Object

Parameters:

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


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

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

#update_test_mapping!(mapping) ⇒ Object

Update #test_mapping

Parameters:

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


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

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