require 'leveldb/leveldb' # the c extension

module LevelDB
class DB
  include Enumerable
  class << self

    ## Loads or creates a LevelDB database as necessary, stored on disk at
    ## +pathname+.
    def new pathname
      make pathname.to_str, true, false
    end

    ## Creates a new LevelDB database stored on disk at +pathname+. Throws an
    ## exception if the database already exists.
    def create pathname
      make pathname.to_str, true, true
    end

    ## Loads a LevelDB database stored on disk at +pathname+. Throws an
    ## exception unless the database already exists.
    def load pathname
      make pathname.to_str, false, false
    end
  end

  alias :includes? :exists?
  alias :contains? :exists?
  alias :member? :exists?
  alias :[] :get
  alias :[]= :put

  def keys; map { |k, v| k } end
  def values; map { |k, v| v } end
end
end

require 'leveldb/leveldb' # the c extension

module LevelDB
class DB
  include Enumerable
  class << self

    ## Loads or creates a LevelDB database as necessary, stored on disk at
    ## +pathname+.
    def new pathname
      make path_string(pathname), true, false
    end

    ## Creates a new LevelDB database stored on disk at +pathname+. Throws an
    ## exception if the database already exists.
    def create pathname
      make path_string(pathname), true, true
    end

    ## Loads a LevelDB database stored on disk at +pathname+. Throws an
    ## exception unless the database already exists.
    def load pathname
      make path_string(pathname), false, false
    end

    private

    ## Coerces the argument into a String for use as a filename/-path
    def path_string pathname
      File.respond_to?(:path) ? File.path(pathname) : pathname.to_str
    end

  end

  alias :includes? :exists?
  alias :contains? :exists?
  alias :member? :exists?
  alias :[] :get
  alias :[]= :put

  def keys; map { |k, v| k } end
  def values; map { |k, v| v } end
end
end

Use File.path to coerce pathname arguments into Strings in 1.9
Use File.path to coerce pathname arguments into Strings in 1.9

The previous commit introduced the use of #to_str on the given pathname
to coerce it into a String, matching the behavior of File.open and other
file handling functions under 1.8.

Ruby 1.9 introduces the File.path method for this purpose and deprecates
the use of #to_str on classes such as Pathname. This commit introduces
a private helper, path_string, that uses File.path when available and
falls back to #to_str otherwise.

Tested with MRI 1.8.7 and 1.9.2.
