Class: DAO
Overview
Data Access Object to manage the persistence layer of the app
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#db ⇒ Redis
An instance from a Redis DB with the redis gem.
-
#type ⇒ String
Type of the stream to identify the database.
Instance Method Summary collapse
-
#clean ⇒ Object
Deletes the keys in the database to starts the FW empty.
-
#connect_database ⇒ Object
Connects to a redis database.
-
#get_status ⇒ String
Retrieves the next status that were saved in the database.
-
#initialize(type = 'twitter') ⇒ DAO
constructor
Config the DAO defining the Data Stream.
-
#publish(usmf) ⇒ Object
Publish a message in the websocket server.
-
#save_status(status) ⇒ Object
Persists the status into the database.
-
#size ⇒ Integer
Returns the size of the database.
Methods included from Logging
Constructor Details
#initialize(type = 'twitter') ⇒ DAO
Config the DAO defining the Data Stream
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/helper/DAO.rb', line 24 def initialize (type = 'twitter') @type = type logger.debug('Starting DAO...') logger.info(type + " DAO in " + type.to_s + " type") logger.info("config loaded OK") connect_database end |
Instance Attribute Details
#db ⇒ Redis
Returns An instance from a Redis DB with the redis gem.
19 20 21 |
# File 'lib/helper/DAO.rb', line 19 def db @db end |
#type ⇒ String
Returns Type of the stream to identify the database.
14 15 16 |
# File 'lib/helper/DAO.rb', line 14 def type @type end |
Instance Method Details
#clean ⇒ Object
if the user develops more Streams, add the new keys like the existing ones
Deletes the keys in the database to starts the FW empty
64 65 66 67 68 |
# File 'lib/helper/DAO.rb', line 64 def clean logger.debug("cleaning the db") @db.del 'twitter' @db.del 'rpg' end |
#connect_database ⇒ Object
Connects to a redis database
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/helper/DAO.rb', line 38 def connect_database @db = Redis.new logger.debug("New instance for Redis") @db = Redis.connect( :db => "#{Settings.redis.db}", :host => "#{Settings.redis.host}", :port => Settings.redis.port, :password => Settings.redis.password ) logger.info("Redis connect OK") end |
#get_status ⇒ String
Retrieves the next status that were saved in the database
56 57 58 59 60 |
# File 'lib/helper/DAO.rb', line 56 def get_status logger.debug("getting status") status = @db.rpop @type status end |
#publish(usmf) ⇒ Object
Publish a message in the websocket server
89 90 91 92 |
# File 'lib/helper/DAO.rb', line 89 def publish usmf logger.info("Publishing") @db.publish 'ws', usmf end |
#save_status(status) ⇒ Object
Persists the status into the database
73 74 75 76 |
# File 'lib/helper/DAO.rb', line 73 def save_status status @db.rpush @type, status logger.info("Status saved") end |
#size ⇒ Integer
Returns the size of the database
81 82 83 84 |
# File 'lib/helper/DAO.rb', line 81 def size logger.debug("getting size") @db.llen @type end |