Class: Mutiny::Mutants::Storage::MutantFile

Inherits:
Object
  • Object
show all
Defined in:
lib/mutiny/mutants/storage/mutant_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mutant_directory) ⇒ MutantFile

Returns a new instance of MutantFile.



12
13
14
# File 'lib/mutiny/mutants/storage/mutant_file.rb', line 12

def initialize(mutant_directory)
  @mutant_directory = mutant_directory
end

Instance Attribute Details

#mutant_directoryObject (readonly)

Returns the value of attribute mutant_directory.



10
11
12
# File 'lib/mutiny/mutants/storage/mutant_file.rb', line 10

def mutant_directory
  @mutant_directory
end

Instance Method Details

#load(absolute_path) ⇒ Object



16
17
18
19
# File 'lib/mutiny/mutants/storage/mutant_file.rb', line 16

def load(absolute_path)
  path = Path.from_absolute(path: absolute_path, root: mutant_directory)
  deep_merge(deserialised_contents(path), deserialised_filename(path))
end

#store(mutant) ⇒ Object



21
22
23
24
25
# File 'lib/mutiny/mutants/storage/mutant_file.rb', line 21

def store(mutant)
  path = Path.from_relative(root: mutant_directory, path: filename.serialise(mutant))
  FileUtils.mkdir_p(File.dirname(path.absolute))
  File.open(path.absolute, 'w') { |f| f.write(contents.serialise(mutant)) }
end