Sha256: 3163fad3efe6e440957c204f1f81085c54eb33a89303cf1c10419c8a7dc42f68

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'penumbra/index'

module Penumbra
  class Catalog
    attr_reader :path

    def initialize(path)
      @path = path
    end

    def [](index_name)
      index_for(index_name)
    end

    def indexes
      @indexes ||= {}
    end

    def index_for(index_name)
      index_name = index_name.to_s
      indexes[index_name] ||= Index.new(File.join(path, index_name))
    end

    def put(index_name, key, value)
      index_for(index_name).put(key, value)
    end

    def get(index_name, key)
      index_for(index_name).get(key)
    end

    def keys_for(index_name)
      index_for(index_name).keys
    end

    def values_for(index_name)
      index_for(index_name).values
    end

    def open
      create_path
      @opened = true
    end

    def close
      raise NotOpenError unless open?
      indexes.values.map(&:close)
    end

    def destroy
      remove_path
    end

    private
    def create_path
      FileUtils.mkdir_p(path)
    end

    def open?
      @opened
    end

    def remove_path
      FileUtils.rm_rf(path)
    end

    class NotOpenError < StandardError ; end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
penumbra-0.1.1 lib/penumbra/catalog.rb