Class: Redis::Database::Watcher
- Inherits:
-
Object
- Object
- Redis::Database::Watcher
- Defined in:
- lib/redis/database.rb
Instance Attribute Summary collapse
-
#bound ⇒ Object
readonly
Returns the value of attribute bound.
Instance Method Summary collapse
- #bind(database, *keys) ⇒ Object
-
#initialize ⇒ Watcher
constructor
A new instance of Watcher.
- #unbind ⇒ Object
Constructor Details
#initialize ⇒ Watcher
Returns a new instance of Watcher.
8 9 10 11 |
# File 'lib/redis/database.rb', line 8 def initialize @watched = [] @bound = true end |
Instance Attribute Details
#bound ⇒ Object (readonly)
Returns the value of attribute bound.
6 7 8 |
# File 'lib/redis/database.rb', line 6 def bound @bound end |
Instance Method Details
#bind(database, *keys) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/redis/database.rb', line 13 def bind database, *keys return unless @bound keys.each do |key| entry = [database, key] next if @watched.include? entry @watched << entry (database.watchers[key] ||= []).push self end end |
#unbind ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/redis/database.rb', line 23 def unbind return unless @bound @watched.each do |database, key| key_df_list = database.watchers[key] next unless key_df_list key_df_list.delete_if { |e| e == self } end @bound = false end |