Module: Cinch::Syncable
Overview
Provide blocking access to user/channel information.
Instance Method Summary collapse
-
#attr(attribute, data = false, unsync = false) ⇒ Object
private
-
#attribute_synced?(attribute) ⇒ Boolean
private
-
#mark_as_synced(attribute)
private
-
#sync(attribute, value, data = false)
private
-
#unsync(attribute)
private
-
#unsync_all
private
-
#wait_until_synced(attr)
private
Blocks until the object is synced.
Instance Method Details
#attr(attribute, data = false, unsync = false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cinch/syncable.rb', line 62 def attr(attribute, data = false, unsync = false) unless unsync if @when_requesting_synced_attribute @when_requesting_synced_attribute.call(attribute) end wait_until_synced(attribute) end if data return @data[attribute] else return instance_variable_get("@#{attribute}") end end |
#attribute_synced?(attribute) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/cinch/syncable.rb', line 41 def attribute_synced?(attribute) @synced_attributes.include?(attribute) end |
#mark_as_synced(attribute)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
79 80 81 |
# File 'lib/cinch/syncable.rb', line 79 def mark_as_synced(attribute) @synced_attributes << attribute end |
#sync(attribute, value, data = false)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
30 31 32 33 34 35 36 37 |
# File 'lib/cinch/syncable.rb', line 30 def sync(attribute, value, data = false) if data @data[attribute] = value else instance_variable_set("@#{attribute}", value) end @synced_attributes << attribute end |
#unsync(attribute)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
47 48 49 |
# File 'lib/cinch/syncable.rb', line 47 def unsync(attribute) @synced_attributes.delete(attribute) end |
#unsync_all
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
54 55 56 |
# File 'lib/cinch/syncable.rb', line 54 def unsync_all @synced_attributes.clear end |
#wait_until_synced(attr)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Blocks until the object is synced.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cinch/syncable.rb', line 8 def wait_until_synced(attr) attr = attr.to_sym waited = 0 while true return if attribute_synced?(attr) waited += 1 if waited % 100 == 0 bot.loggers.warn "A synced attribute ('%s' for %s) has not been available for %d seconds, still waiting" % [attr, self.inspect, waited / 10] bot.loggers.warn caller.map {|s| " #{s}"} if waited / 10 >= 30 bot.loggers.warn " Giving up..." raise Exceptions::SyncedAttributeNotAvailable, "'%s' for %s" % [attr, self.inspect] end end sleep 0.1 end end |