1 # -*- encoding: binary -*-
6 include Metropolis::Common
7 autoload :Single, 'metropolis/tdb/single'
8 autoload :Multi, 'metropolis/tdb/multi'
12 @tdb_opts = { :tdb_flags => 0 }
14 @tdb_opts[:open_flags] = IO::RDONLY
15 extend Metropolis::Common::RO
18 size = @query['hash_size'] and @tdb_opts[:hash_size] = size.to_i
19 hash = @query['hash'] and @tdb_opts[:hash] = hash.to_sym
21 case @query['volatile']
22 when 'true'; @tdb_opts[:tdb_flags] |= TDB::VOLATILE
25 raise ArgumentError, "'volatile' must be 'true' or 'false'"
30 when 'false'; @tdb_opts[:tdb_flags] |= TDB::NOSYNC
32 raise ArgumentError, "'sync' must be 'true' or 'false'"
35 extend(@path_pattern ? Metropolis::TDB::Multi : Metropolis::TDB::Single)
39 value = env["rack.input"].read
41 case env['HTTP_X_TT_PDMODE']
43 # TODO: make this atomic
44 return r(409) if tdb.include?(key)
46 value = (tdb.get(key) || "") << value
54 r(db(key) { |tdb| tdb.nuke!(key) } ? 200 : 404)
58 value = db(key) { |tdb| tdb.fetch(key) } or return r(404)
59 [ 200, { 'Content-Length' => value.size.to_s }.merge!(@headers), [ value ] ]