Module: Cinch::Syncable

Included in:
Channel, User
Defined in:
lib/cinch/syncable.rb

Instance Method Summary collapse

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.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cinch/syncable.rb', line 46

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

#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.



63
64
65
# File 'lib/cinch/syncable.rb', line 63

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.



17
18
19
20
21
22
23
24
# File 'lib/cinch/syncable.rb', line 17

def sync(attribute, value, data = false)
  if data
    @data[attribute] = value
  else
    instance_variable_set("@#{attribute}", value)
  end
  @synced_attributes << attribute
end

#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.

Returns:

  • (Boolean)


28
29
30
# File 'lib/cinch/syncable.rb', line 28

def synced?(attribute)
  @synced_attributes.include?(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.



34
35
36
# File 'lib/cinch/syncable.rb', line 34

def unsync(attribute)
  @synced_attributes.delete(attribute)
end

#unsync_allvoid

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.

Since:

  • 1.0.1



41
42
43
# File 'lib/cinch/syncable.rb', line 41

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.



7
8
9
10
11
12
13
# File 'lib/cinch/syncable.rb', line 7

def wait_until_synced(attr)
  attr = attr.to_sym
  while true
    return if @synced_attributes.include?(attr)
    sleep 0.1
  end
end