Module: Gonzui::BDBExtension

Defined in:
lib/gonzui/bdbdbm.rb

Instance Method Summary collapse

Instance Method Details

#delete_both(key, value) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/gonzui/bdbdbm.rb', line 98

def delete_both(key, value)
  cursor = self.cursor
  begin
    pair = cursor.get(BDB::GET_BOTH, key, value)
    cursor.delete unless pair.nil?
  ensure
    cursor.close
  end
end

#duplicates(key, assoc = false) ⇒ Object



77
78
79
# File 'lib/gonzui/bdbdbm.rb', line 77

def duplicates(key , assoc = false)
	super(key, assoc)
end

#each_by_prefix(prefix) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gonzui/bdbdbm.rb', line 81

def each_by_prefix(prefix)
  values = []
  cursor = self.cursor
  begin
    if pair = cursor.set_range(prefix)
      begin
        k, v = pair
        break unless k[0, prefix.length] == prefix
        yield(k, v)
      end while pair = cursor.next
    end
    return values
  ensure
    cursor.close
  end
end

#get_last_keyObject



108
109
110
111
112
113
114
115
116
# File 'lib/gonzui/bdbdbm.rb', line 108

def get_last_key
  cursor = self.cursor
  begin
    k, v = cursor.last
    return k
  ensure
    cursor.close
  end
end