Sha256: b285c2391048f13742c6b805d9e55dbd7e93c265881f12c6e23dc49133498d9b
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
require 'fileutils' require 'yaml/store' require_relative 'mapper' require_relative 'settings' require_relative 'sig_finder' require_relative 'signature' require_relative 'tags' module Signore class Repo def initialize(path: Settings.new.repo_path, sig_finder: SigFinder) @path = path @sig_finder = sig_finder initialise_store if path.zero? or not path.exist? @store = YAML::Store.new(path) end def <<(sig) sigs << sig persist end def find(tags: Tags.new) sig_finder.find(sigs, tags: tags) end def sigs @sigs ||= store.transaction(true) { store['signatures'] }.map do |elem| elem.is_a?(Signature) ? elem : Mapper.from_h(elem) end end attr_reader :path, :sig_finder, :store private :path, :sig_finder, :store private def initialise_store FileUtils.mkdir_p path.dirname FileUtils.touch path YAML::Store.new(path).transaction { |store| store['signatures'] = [] } end def persist hashes = sigs.map { |sig| Mapper.to_h(sig) } store.transaction { store['signatures'] = hashes } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
signore-0.3.2 | lib/signore/repo.rb |