Class: Clipcellar::GroongaDatabase

Inherits:
Object
  • Object
show all
Defined in:
lib/clipcellar/groonga_database.rb

Instance Method Summary collapse

Constructor Details

#initializeGroongaDatabase

Returns a new instance of GroongaDatabase.



21
22
23
# File 'lib/clipcellar/groonga_database.rb', line 21

def initialize
  @database = nil
end

Instance Method Details

#add(id, text, time) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/clipcellar/groonga_database.rb', line 44

def add(id, text, time)
  clipboards.add(id,
                 {
                   :text       => text,
                   :created_at => time,
                 })
end

#clipboardsObject



65
66
67
# File 'lib/clipcellar/groonga_database.rb', line 65

def clipboards
  @clipboards ||= Groonga["Clipboards"]
end

#closeObject



56
57
58
59
# File 'lib/clipcellar/groonga_database.rb', line 56

def close
  @database.close
  @database = nil
end

#closed?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/clipcellar/groonga_database.rb', line 61

def closed?
  @database.nil? or @database.closed?
end

#delete(id) ⇒ Object



52
53
54
# File 'lib/clipcellar/groonga_database.rb', line 52

def delete(id)
  clipboards.delete(id)
end

#dumpObject



69
70
71
# File 'lib/clipcellar/groonga_database.rb', line 69

def dump
  Groonga::DatabaseDumper.dump
end

#open(base_path, encoding = :utf8) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/clipcellar/groonga_database.rb', line 25

def open(base_path, encoding=:utf8)
  reset_context(encoding)
  path = File.join(base_path, "clipcellar.db")
  if File.exist?(path)
    @database = Groonga::Database.open(path)
    populate_schema
  else
    FileUtils.mkdir_p(base_path)
    populate(path)
  end
  if block_given?
    begin
      yield(self)
    ensure
      close unless closed?
    end
  end
end