metropolis.git  about / heads / tags
key-value store for Rack
blob 7054883da0b1b98d98625749c5da2dd9b2a7cf8a 661 bytes (raw)
$ git show HEAD:lib/metropolis/multi_hash.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
# -*- encoding: binary -*-
# :enddoc:
module Metropolis::MultiHash
  autoload :Digest, 'metropolis/multi_hash/digest'
  autoload :ToI, 'metropolis/multi_hash/to_i'

  def self.extended(obj)
    sym = obj.instance_eval {
      case @multi_hash.to_s
      when /\Ato_i/
        extend Metropolis::MultiHash::ToI
      when /\Adigest_/
        extend Metropolis::MultiHash::Digest
      when /\Atdb_hash_/
        extend TDB::HashFunctions
      end
      @multi_hash
    }
    obj.respond_to?(sym) or
      raise ArgumentError, "multi_hash=#{sym} not supported"
    (class << obj; self; end).instance_eval do
      alias_method :multi_hash, sym
    end
  end
end

git clone https://yhbt.net/metropolis.git