Skip to content

Commit

Permalink
Refactor save! and load! methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 3, 2019
1 parent 1a58891 commit 8b9775c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/covered/persist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

module Covered
class Persist < Wrapper
def initialize(output, path: ".covered")
def initialize(output, path = ".covered")
super(output)

@path = path
Expand All @@ -46,9 +46,7 @@ def serialize(coverage)
}
end

def enable
super

def load!(path = @path)
return unless File.exist?(@path)

# Load existing coverage information and mark all files:
Expand All @@ -57,9 +55,7 @@ def enable
end
end

def disable
super

def save!(path = @path)
# Dump all coverage:
File.open(@path, "w") do |file|
packer = make_packer(file)
Expand All @@ -72,6 +68,18 @@ def disable
end
end

def enable
super

load!
end

def disable
super

save!
end

def make_packer(io)
packer = MessagePack::Packer.new(io)
packer.register_type(0x00, Symbol, :to_msgpack_ext)
Expand Down

0 comments on commit 8b9775c

Please sign in to comment.