Class: ThreadPartyProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/threadparty/threadpartyproxy.rb

Overview

The DSL resolver for ThreadParty.

It handles adding classes that inherited PartyProxy to the DSL, and executing them

Constant Summary collapse

@@proxables =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool_party) ⇒ ThreadPartyProxy

Returns a new instance of ThreadPartyProxy.



13
14
15
# File 'lib/threadparty/threadpartyproxy.rb', line 13

def initialize(pool_party)
  @thread_party = pool_party
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/threadparty/threadpartyproxy.rb', line 21

def method_missing(name, *args, &block)
  if @@proxables.has_key?(name) then
    perform_proxy(name, &block)
  else
    raise ArgumentError, "The bouncer says \"#{name}\" is not allowed at the thread party.\nIt is not inherited from PartyProxy"
  end
end

Class Method Details

.add_proxy_reciever(klass) ⇒ Object



17
18
19
# File 'lib/threadparty/threadpartyproxy.rb', line 17

def self.add_proxy_reciever(klass)
  @@proxables[klass.name.to_sym] = klass
end

Instance Method Details

#perform_proxy(a_class, &block) ⇒ Object



29
30
31
32
33
# File 'lib/threadparty/threadpartyproxy.rb', line 29

def perform_proxy(a_class, &block)
  party = @@proxables[a_class].new
  party.instance_eval(&block)
  @thread_party.to_process << party
end