Class: ActiveGroonga::Database — activegroonga - ラングバ

Class: ActiveGroonga::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/active_groonga/database.rb

Instance Method Summary (collapse)

Constructor Details

- (Database) initialize(path)

Returns a new instance of Database



20
21
22
23
# File 'lib/active_groonga/database.rb', line 20

def initialize(path)
  @path = path
  @database = nil
end

Instance Method Details

- (Object) close



44
45
46
47
48
# File 'lib/active_groonga/database.rb', line 44

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

- (Object) ensure_available



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_groonga/database.rb', line 25

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

- (Object) remove



37
38
39
40
41
42
# File 'lib/active_groonga/database.rb', line 37

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

- (Object) reopen



50
51
52
53
# File 'lib/active_groonga/database.rb', line 50

def reopen
  close
  ensure_available
end