forked from toptal/crystalball
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Map concept so we can customize the way how & when we dump the ma…
…p to our storage
- Loading branch information
Showing
7 changed files
with
80 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
AllCops: | ||
DisplayCopNames: true | ||
TargetRubyVersion: 2.3 | ||
Style/GuardClause: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Crystalball | ||
class MapGenerator | ||
class SimpleMap | ||
def initialize(storage) | ||
@storage = storage | ||
@raw_map = {} | ||
end | ||
|
||
def load | ||
self.raw_map = storage.load | ||
end | ||
|
||
def stash(case_map) | ||
raw_map[case_map.case_uid] = case_map.coverage | ||
end | ||
|
||
def dump | ||
storage.dump raw_map | ||
end | ||
|
||
def clear! | ||
self.raw_map = {} | ||
end | ||
|
||
private | ||
|
||
attr_accessor :raw_map, :storage | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Crystalball | ||
class MapGenerator | ||
class StandardMap < SimpleMap | ||
def initialize(storage, dump_threshold: 100) | ||
super(storage) | ||
@dump_threshold = dump_threshold | ||
end | ||
|
||
def stash(case_map) | ||
super | ||
if raw_map.size >= dump_threshold | ||
dump | ||
clear! | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :dump_threshold | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters