Sha256: aae16415d4b4e75f7efa37cc6fa03a5f39fc58893bbabd95d2ee06ffdf5a7061

Contents?: true

Size: 587 Bytes

Versions: 2

Compression:

Stored size: 587 Bytes

Contents

module Signore class Database
  def initialize path
    @store = YAML::Store.new path
  end

  def << sig
    store.transaction do
      store['signatures'] ||= []
      store['signatures'] << sig
    end
  end

  def find forbidden_tags: [], random: Random.new, required_tags: []
    store.transaction true do
      store['signatures']
        .select { |sig| required_tags.all?  { |tag| sig.tagged_with? tag } }
        .reject { |sig| forbidden_tags.any? { |tag| sig.tagged_with? tag } }
        .sample random: random
    end
  end

  attr_reader :store
  private     :store
end end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
signore-0.2.2 lib/signore/database.rb
signore-0.2.1 lib/signore/database.rb