Class: Clipcellar::GroongaDatabase
- Inherits:
-
Object
- Object
- Clipcellar::GroongaDatabase
- Defined in:
- lib/clipcellar/groonga_database.rb
Instance Method Summary collapse
- #add(id, text, time) ⇒ Object
- #clipboards ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #delete(id) ⇒ Object
- #dump ⇒ Object
-
#initialize ⇒ GroongaDatabase
constructor
A new instance of GroongaDatabase.
- #open(base_path, encoding = :utf8) ⇒ Object
Constructor Details
#initialize ⇒ GroongaDatabase
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 |
#clipboards ⇒ Object
65 66 67 |
# File 'lib/clipcellar/groonga_database.rb', line 65 def clipboards @clipboards ||= Groonga["Clipboards"] end |
#close ⇒ Object
56 57 58 59 |
# File 'lib/clipcellar/groonga_database.rb', line 56 def close @database.close @database = nil end |
#closed? ⇒ 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 |
#dump ⇒ Object
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 |