Sha256: 76a6d4e0adb503f6536fbc37cbecd8ac2896a8d2bd0dfcc368ff6729a1312923

Contents?: true

Size: 1.55 KB

Versions: 11

Compression:

Stored size: 1.55 KB

Contents

# Copyright (C) 2010  Kouhei Sutou <kou@clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

require 'fileutils'

module ActiveGroonga
  class Database
    def initialize(path)
      @path = path
      @database = nil
    end

    def ensure_available
      return if @database
      if @path.exist?
        @database = Groonga::Database.open(@path.to_s,
                                           :context => Base.context)
      else
        FileUtils.mkdir_p(@path.dirname) unless @path.dirname.exist?
        @database = Groonga::Database.create(:path => @path.to_s,
                                             :context => Base.context)
      end
    end

    def remove
      ensure_available if @path.exist?
      return if @database.nil?
      @database.remove
      @database = nil
    end

    def close
      return if @database.nil?
      @database.close
      @database = nil
    end

    def reopen
      close
      ensure_available
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
activegroonga-2.1.4 lib/active_groonga/database.rb
activegroonga-2.1.3 lib/active_groonga/database.rb
activegroonga-2.1.2 lib/active_groonga/database.rb
activegroonga-2.1.1 lib/active_groonga/database.rb
activegroonga-1.0.7 lib/active_groonga/database.rb
activegroonga-1.0.6 lib/active_groonga/database.rb
activegroonga-1.0.5 lib/active_groonga/database.rb
activegroonga-1.0.4 lib/active_groonga/database.rb
activegroonga-1.0.3 lib/active_groonga/database.rb
activegroonga-1.0.1 lib/active_groonga/database.rb
activegroonga-1.0.0 lib/active_groonga/database.rb