### Home Classes Methods

### In Files

- lib/xmpp4r/observable/observable_thing.rb

### Methods

- #add_observer
- #changed
- #changed?
- #count_notifications
- #count_observers
- #delete_observer
- #delete_observers
- #notify_observers
- #pending_notifications?
- #wait_notifications

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# ObservableThing

# XMPP4R - XMPP Library for Ruby

This file's copyright (c) 2009 by Pablo Lorenzzoni <pablo@propus.com.br>

License | Ruby's license (see the LICENSE file) or GNU GPL, at your option.

Website::http://xmpp4r.github.io

This was based on Observable module from Ruby.

### Public Instance Methods

add_observer(thing, observer, func = :update) click to toggle source

Adds an observer for some "thing".

thing | what will be observed.
observer | the observer.
func | the observer method that will be called (default: :update).

    # File lib/xmpp4r/observable/observable_thing.rb, line 16
    def add_observer(thing, observer, func = :update)
      @things = {} unless defined? @things
      @things[thing] = {} unless ! @things[thing].nil?
      unless observer.respond_to? func
        raise NoMethodError, "observer does not respond to `#{func.to_s}'"
      end
      @things[thing][observer] = func unless @things[thing].include?(observer)
    end

changed(thing, state = true) click to toggle source

Change the state of some "thing".

thing | what will have the state changed.
state | the state (default = true).

    # File lib/xmpp4r/observable/observable_thing.rb, line 72
    def changed(thing, state = true)
      @things_state = {} unless defined? @things_state
      @things_state[thing] = state
    end

changed?(thing) click to toggle source

Check the state of some "thing".

thing: what to have its state checked.

    # File lib/xmpp4r/observable/observable_thing.rb, line 80
    def changed?(thing)
      if defined? @things_state and @things_state[thing]
        true
      else
        false
      end
    end

count_notifications(thing) click to toggle source

Count the number of notifications for some "thing".

thing | what has been observed.

    # File lib/xmpp4r/observable/observable_thing.rb, line 63
    def count_notifications(thing)
      return 0 if (! defined?(@things_counter)) or (! @things_counter.include?(thing))
      @things_counter[thing]
    end

count_observers(thing = nil) click to toggle source

Count the number of observers for some "thing".

thing | what has been observed (if nil, count all observers).

    # File lib/xmpp4r/observable/observable_thing.rb, line 47
    def count_observers(thing = nil)
      return 0 if ! defined? @things
      size = 0
      if thing.nil?
        @things.each { |thing, hash|
          size += hash.size
        }
      else
        size = @things[thing].size unless @things[thing].nil?
      end
      size
    end

delete_observer(thing, observer) click to toggle source

Deletes an observer for some "thing".

thing | what has been observed.
observer | the observer.

    # File lib/xmpp4r/observable/observable_thing.rb, line 29
    def delete_observer(thing, observer)
      @things[thing].delete observer if defined? @things and ! @things[thing].nil?
    end

delete_observers(thing = nil) click to toggle source

Delete observers for some "thing".

thing | what has been observed (if nil, deletes all observers).

    # File lib/xmpp4r/observable/observable_thing.rb, line 36
    def delete_observers(thing = nil)
      if thing.nil?
        @things.clear if defined? @things
      else
        @things[thing].clear if defined? @things and ! @things[thing].nil?
      end
    end

notify_observers(thing, *arg) click to toggle source

Notify all observers of "thing" about something. This will only be enforced if the state of that "thing" is true. Also, if the observer returns the Symbol :delete_me, it will be deleted after being notified.

thing | what has been observed.
args | notification to be sent to the observers of "thing".

    # File lib/xmpp4r/observable/observable_thing.rb, line 94
    def notify_observers(thing, *arg)
      if changed?(thing)
        if defined? @things and ! @things[thing].nil?
          @things[thing].each { |observer, func|
            increase_counter(thing)
            @thread_store = ThreadStore.new if ! defined? @thread_store
            @thread_store.add Thread.new {
              if observer.send(func, thing, *arg) == :delete_me
                delete_observer(thing, observer)
              end
            }
          }
        end
        changed(thing, false)
      end
    end

pending_notifications?() click to toggle source

Is there pending notifications?

    # File lib/xmpp4r/observable/observable_thing.rb, line 112
    def pending_notifications?
      return false if ! defined? @thread_store
      @thread_store.size > 0
    end

wait_notifications() click to toggle source

Wait all notifications

    # File lib/xmpp4r/observable/observable_thing.rb, line 118
    def wait_notifications
      sleep 1 while pending_notifications?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.