Class: AgentXmpp::Delegate

Inherits:
Object show all
Defined in:
lib/agent_xmpp/client/response.rb

Overview


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDelegate

.….….….….….….….….….….….….….….….….….….….….….….….….….….



67
68
69
# File 'lib/agent_xmpp/client/response.rb', line 67

def initialize
  @methods = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



93
94
95
# File 'lib/agent_xmpp/client/response.rb', line 93

def method_missing(meth, *args, &blk)
  methods.send(meth, *args, &blk)
end

Instance Attribute Details

#methodsObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….….….



64
65
66
# File 'lib/agent_xmpp/client/response.rb', line 64

def methods
  @methods
end

Instance Method Details

#add_delegate_methods(methods) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



72
73
74
# File 'lib/agent_xmpp/client/response.rb', line 72

def add_delegate_methods(methods)
  @methods << methods
end

#delegate(pipe, delegate) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/agent_xmpp/client/response.rb', line 77

def delegate(pipe, delegate)
  methods.each do |meths|
    meths.each do |(meth,blk)|
      delegate.define_meta_class_method(meth) do |*args|
        if res = blk.call(*args)
          pipe.send_resp(res)             
          pipe.remove_delegate(delegate)
        end
      end
    end
    pipe.add_delegate(delegate)
  end
  methods.clear
end