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  | 
    
      # File 'lib/helper/DAO.rb', line 24 def initialize (type = 'twitter') @type = type 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
      58 59 60 61 62 63  | 
    
      # File 'lib/helper/DAO.rb', line 58 def clean @db.del 'twitter' @db.del 'rpg' end  | 
  
#connect_database ⇒ Object
Connects to a redis database
      33 34 35 36 37 38 39 40 41 42 43 44  | 
    
      # File 'lib/helper/DAO.rb', line 33 def connect_database @db = Redis.new @db = Redis.connect( :db => "#{Settings.redis.db}", :host => "#{Settings.redis.host}", :port => Settings.redis.port, :password => Settings.redis.password ) end  | 
  
#get_status ⇒ String
Retrieves the next status that were saved in the database
      49 50 51 52 53 54  | 
    
      # File 'lib/helper/DAO.rb', line 49 def get_status status = @db.rpop @type status end  | 
  
#publish(usmf) ⇒ Object
Publish a message in the websocket server
      84 85 86  | 
    
      # File 'lib/helper/DAO.rb', line 84 def publish usmf @db.publish 'ws', usmf end  | 
  
#save_status(status) ⇒ Object
Persists the status into the database
      68 69 70 71 72  | 
    
      # File 'lib/helper/DAO.rb', line 68 def save_status status @db.rpush @type, status end  | 
  
#size ⇒ Integer
Returns the size of the database
      77 78 79  | 
    
      # File 'lib/helper/DAO.rb', line 77 def size @db.llen @type end  |