Skip to content

Commit

Permalink
Use a PStore to help store our details between runs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspth committed Oct 17, 2023
1 parent a860eee commit 3d93c13
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/oaken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,48 @@ def load_each
end
end

require "fileutils"
require "pstore"

class Entry
def self.within(directory)
Pathname.glob("#{directory}{,/**/*}.rb").sort.map { new _1 }
end

def initialize(pathname)
@file, @pathname = pathname.to_s, pathname
FileUtils.mkdir_p("tmp/oaken/" + @pathname.dirname.to_s)
@store = PStore.new("tmp/oaken/" + @file)
end

def load_onto(seeds)
seeds.class_eval @pathname.read, @file
@store.transaction do
if replay?
p "replaying #{@file}…"
@store[:readers].each do |key, name, id, lineno|
seeds.send(key).instance_eval "def #{name}() = find #{id}", @file, lineno
end
else
@store[:checksum] = checksum
@store[:readers] = []

seeds.class_eval @pathname.read, @file
end
end
end

def replay?
@store[:checksum] == checksum
end

def checksum
Digest::MD5.hexdigest(@pathname.read)
end

def define_reader(stored, name, id)
lineno = self.lineno
stored.instance_eval "def #{name}() = find #{id}", @file, lineno
@store[:readers] << [stored.key, name, id, lineno]
end

def lineno
Expand Down

0 comments on commit 3d93c13

Please sign in to comment.