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.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cinch/syncable.rb', line 65 def attr(attribute, data = false, unsync = false) unless unsync @when_requesting_synced_attribute&.call(attribute) wait_until_synced(attribute) end if data @data[attribute] else 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.
44 45 46 |
# File 'lib/cinch/syncable.rb', line 44 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.
80 81 82 |
# File 'lib/cinch/syncable.rb', line 80 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.
33 34 35 36 37 38 39 40 |
# File 'lib/cinch/syncable.rb', line 33 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.
50 51 52 |
# File 'lib/cinch/syncable.rb', line 50 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.
57 58 59 |
# File 'lib/cinch/syncable.rb', line 57 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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cinch/syncable.rb', line 10 def wait_until_synced(attr) attr = attr.to_sym waited = 0 loop do 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, 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, inspect] end end sleep 0.1 end end |