Class: FSDBM

Inherits:
Object
  • Object
show all
Defined in:
lib/refe/fsdbm.rb

Instance Method Summary collapse

Constructor Details

#initialize(basedir) ⇒ FSDBM

Returns a new instance of FSDBM.



25
26
27
28
# File 'lib/refe/fsdbm.rb', line 25

def initialize( basedir )
  @basedir = basedir
  @base_re = %r<\A#{@basedir}/>
end

Instance Method Details

#[](*keys) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/refe/fsdbm.rb', line 30

def []( *keys )
  path = keys_to_path(keys)
  if FileTest.file?(path)
    File.open(path) {|f|
        return f.read
    }
  elsif FileTest.directory?(path)
    return nil unless File.file?(path + '/-')
    File.open(path + '/-') {|f|
        return f.read
    }
  else
    nil
  end
end

#[]=(*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/refe/fsdbm.rb', line 46

def []=( *args )
  val = args.pop
  setup_dirs args[0..-2]
  path = keys_to_path(args)
  begin
    # $stderr.puts "Warning: exist: #{path}" if File.file?(path)
    File.open(path, 'w') {|f|
        f.write val
    }
  rescue Errno::EISDIR
    # $stderr.puts "Warning: exist: #{path}/-" if File.file?(path + '/-')
    File.open(path + '/-', 'w') {|f|
        f.write val
    }
  end
  val
end