Class: Rssdump::MongoStore
- Inherits:
-
Object
- Object
- Rssdump::MongoStore
- Defined in:
- lib/rssdump/mongo_store.rb
Constant Summary collapse
- DEFAULT_URL =
"mongodb://127.0.0.1:27017/rssdump"- COLL_ITEMS =
"items"
Instance Method Summary collapse
- #disk_usage_mb ⇒ Object
-
#initialize(url) ⇒ MongoStore
constructor
A new instance of MongoStore.
- #nb_items ⇒ Object
- #upsert(item) ⇒ Object
Constructor Details
#initialize(url) ⇒ MongoStore
Returns a new instance of MongoStore.
8 9 10 11 12 13 |
# File 'lib/rssdump/mongo_store.rb', line 8 def initialize url @url = url || DEFAULT_URL client[COLL_ITEMS].indexes.create_one({ :link => 1 }, :unique => true) client[COLL_ITEMS].indexes.create_one({ :pub_date => 1 }, :unique => false) @logger = Logging.logger[self] end |
Instance Method Details
#disk_usage_mb ⇒ Object
38 39 40 |
# File 'lib/rssdump/mongo_store.rb', line 38 def disk_usage_mb client.database.command({dbStats: 1, scale: 1024**2}).first["dataSize"] end |
#nb_items ⇒ Object
34 35 36 |
# File 'lib/rssdump/mongo_store.rb', line 34 def nb_items client[COLL_ITEMS].count end |
#upsert(item) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rssdump/mongo_store.rb', line 15 def upsert item if client[COLL_ITEMS].find({link: item.link}).count == 0 @logger.debug "Inserting new item #{item.link} to store" client[COLL_ITEMS].insert_one({ v: Rssdump::VERSION, title: item.title, link: item.link, feed: item.feed, feed_name: item.feed_name, category: item.category, description: item.description, pub_date: item.pub_date, }) true else false end end |