Class: Feedcellar::GroongaDatabase
- Inherits:
-
Object
- Object
- Feedcellar::GroongaDatabase
- Defined in:
- lib/feedcellar/groonga_database.rb
Instance Method Summary collapse
- #add(resource, title, link, description, date) ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #feeds ⇒ Object
-
#initialize ⇒ GroongaDatabase
constructor
A new instance of GroongaDatabase.
- #open(base_path, encoding = :utf8) ⇒ Object
- #register(key, attributes) ⇒ Object
- #resources ⇒ Object
Constructor Details
#initialize ⇒ GroongaDatabase
Returns a new instance of GroongaDatabase.
5 6 7 |
# File 'lib/feedcellar/groonga_database.rb', line 5 def initialize @database = nil end |
Instance Method Details
#add(resource, title, link, description, date) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/feedcellar/groonga_database.rb', line 33 def add(resource, title, link, description, date) feeds = Groonga["Feeds"] feeds.add(link, :resource => resource, :title => title, :link => link, :description => description, :date => date) end |
#close ⇒ Object
42 43 44 45 |
# File 'lib/feedcellar/groonga_database.rb', line 42 def close @database.close @database = nil end |
#closed? ⇒ Boolean
47 48 49 |
# File 'lib/feedcellar/groonga_database.rb', line 47 def closed? @database.nil? or @database.closed? end |
#feeds ⇒ Object
55 56 57 |
# File 'lib/feedcellar/groonga_database.rb', line 55 def feeds @feeds ||= Groonga["Feeds"] end |
#open(base_path, encoding = :utf8) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/feedcellar/groonga_database.rb', line 9 def open(base_path, encoding=:utf8) reset_context(encoding) path = File.join(base_path, "feedcellar.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 |
#register(key, attributes) ⇒ Object
28 29 30 31 |
# File 'lib/feedcellar/groonga_database.rb', line 28 def register(key, attributes) feeds = Groonga["Resources"] feeds.add(key, attributes) end |
#resources ⇒ Object
51 52 53 |
# File 'lib/feedcellar/groonga_database.rb', line 51 def resources @resources ||= Groonga["Resources"] end |