Class: Cinch::Plugins::TwitterWatch::Cache
- Inherits:
-
Object
- Object
- Cinch::Plugins::TwitterWatch::Cache
- Defined in:
- lib/cinch/plugins/twitterwatch/cache.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#client ⇒ Object
Returns the value of attribute client.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#tweet_cache ⇒ Object
Returns the value of attribute tweet_cache.
Instance Method Summary collapse
- #cache_tweet(tweet_id) ⇒ Object
- #init_cache ⇒ Object
-
#initialize(nick, channel, client) ⇒ Cache
constructor
A new instance of Cache.
- #tweet_unless_cached(tweet_id) ⇒ Object
Constructor Details
#initialize(nick, channel, client) ⇒ Cache
Returns a new instance of Cache.
6 7 8 9 10 11 |
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 6 def initialize(nick, channel, client) @nick = nick @client = client @channel = channel @tweet_cache = {} end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
4 5 6 |
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 4 def channel @channel end |
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 4 def client @client end |
#nick ⇒ Object
Returns the value of attribute nick.
4 5 6 |
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 4 def nick @nick end |
#tweet_cache ⇒ Object
Returns the value of attribute tweet_cache.
4 5 6 |
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 4 def tweet_cache @tweet_cache end |
Instance Method Details
#cache_tweet(tweet_id) ⇒ Object
29 30 31 32 |
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 29 def cache_tweet(tweet_id) @tweet_cache[tweet_id.to_i] = true true end |
#init_cache ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 13 def init_cache @client.user_timeline(@nick).each do |tweet| cache_tweet(tweet.id) end "Cache: [#{@nick}]: #{@tweet_cache.count} tweets cached." rescue Twitter::Error::NotFound debug "You have set an invalid or protected user (#{@nick}) to " + ' watch, please correct this error' end |
#tweet_unless_cached(tweet_id) ⇒ Object
23 24 25 26 27 |
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 23 def tweet_unless_cached(tweet_id) return if @tweet_cache.key?(tweet_id) cache_tweet(tweet_id) @client.status(tweet_id).text end |