Class: Feedcellar::GroongaDatabase
- Inherits:
-
Object
- Object
- Feedcellar::GroongaDatabase
- Defined in:
- lib/feedcellar/groonga_database.rb
Instance Method Summary collapse
- #add(resource_key, title, link, description, date) ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #dump ⇒ Object
- #feeds ⇒ Object
-
#initialize ⇒ GroongaDatabase
constructor
A new instance of GroongaDatabase.
- #open(base_path, encoding = :utf8) ⇒ Object
- #register(key, attributes) ⇒ Object
- #resources ⇒ Object
- #unregister(title_or_url) ⇒ 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_key, title, link, description, date) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/feedcellar/groonga_database.rb', line 38 def add(resource_key, title, link, description, date) feeds.add(link, :resource => resources[resource_key], :title => title, :link => link, :description => description, :date => date) end |
#close ⇒ Object
53 54 55 56 |
# File 'lib/feedcellar/groonga_database.rb', line 53 def close @database.close @database = nil end |
#closed? ⇒ Boolean
58 59 60 |
# File 'lib/feedcellar/groonga_database.rb', line 58 def closed? @database.nil? or @database.closed? end |
#dump ⇒ Object
70 71 72 |
# File 'lib/feedcellar/groonga_database.rb', line 70 def dump Groonga::DatabaseDumper.dump end |
#feeds ⇒ Object
66 67 68 |
# File 'lib/feedcellar/groonga_database.rb', line 66 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 27 28 29 30 31 32 |
# 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) begin populate_schema rescue Groonga::Schema::ColumnCreationWithDifferentOptions # NOTE: migrate to feedcellar-0.3.0 from 0.2.2 or earlier. populate_new_schema transform_resources_key end 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
34 35 36 |
# File 'lib/feedcellar/groonga_database.rb', line 34 def register(key, attributes) resources.add(key, attributes) end |
#resources ⇒ Object
62 63 64 |
# File 'lib/feedcellar/groonga_database.rb', line 62 def resources @resources ||= Groonga["Resources"] end |
#unregister(title_or_url) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/feedcellar/groonga_database.rb', line 46 def unregister(title_or_url) resources.delete do |record| (record.title == title_or_url) | (record.xmlUrl == title_or_url) end end |