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) ⇒ void private
- #sync(attribute, value, data = false) ⇒ void private
- #unsync(attribute) ⇒ void private
- #unsync_all ⇒ void private
-
#wait_until_synced(attr) ⇒ void
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.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cinch/syncable.rb', line 64 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.
43 44 45 |
# File 'lib/cinch/syncable.rb', line 43 def attribute_synced?(attribute) @synced_attributes.include?(attribute) end |
#mark_as_synced(attribute) ⇒ void
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) ⇒ void
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.
32 33 34 35 36 37 38 39 |
# File 'lib/cinch/syncable.rb', line 32 def sync(attribute, value, data = false) if data @data[attribute] = value else instance_variable_set("@#{attribute}", value) end @synced_attributes << attribute end |
#unsync(attribute) ⇒ void
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.
49 50 51 |
# File 'lib/cinch/syncable.rb', line 49 def unsync(attribute) @synced_attributes.delete(attribute) end |
#unsync_all ⇒ void
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.
56 57 58 |
# File 'lib/cinch/syncable.rb', line 56 def unsync_all @synced_attributes.clear end |
#wait_until_synced(attr) ⇒ void
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 |
# 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 |