Class: Jabber::Framework::Base
- Defined in:
- lib/gems/xmpp4r-0.4/lib/xmpp4r/framework/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#stream ⇒ Object
Returns the value of attribute stream.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(stream) ⇒ Base
constructor
A new instance of Base.
- #on_unhandled_iq(iq) ⇒ Object
Constructor Details
#initialize(stream) ⇒ Base
Returns a new instance of Base.
31 32 33 34 35 36 37 38 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/framework/base.rb', line 31 def initialize(stream) @stream = stream @helpers = {} @helpers_lock = Mutex.new # Catch all unhandled iq stanzas (lowest priority) @stream.add_iq_callback(-1000, self, &method(:on_unhandled_iq)) end |
Instance Attribute Details
#stream ⇒ Object
Returns the value of attribute stream.
29 30 31 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/framework/base.rb', line 29 def stream @stream end |
Class Method Details
.helper(name, klass = nil, &factory) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/framework/base.rb', line 7 def self.helper(name, klass=nil, &factory) if klass.nil? and factory.nil? raise "helper #{name} needs a class or factory" end define_method(name) do @helpers_lock.synchronize do if @helpers[name] @helpers[name] else if factory @helpers[name] = instance_eval { factory.call(@stream) } elsif klass @helpers[name] = klass.new(@stream) else raise end end end end end |
Instance Method Details
#on_unhandled_iq(iq) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/framework/base.rb', line 40 def on_unhandled_iq(iq) if iq.type == :get or iq.type == :set answer = iq.answer(true) answer.type = :error answer.add(ErrorResponse.new('feature-not-implemented')) @stream.send(answer) true else false end end |