Class: PartyProxy

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

Direct Known Subclasses

ProcessQueue

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePartyProxy

Returns a new instance of PartyProxy.



57
58
59
60
61
# File 'lib/threadparty/partyproxy.rb', line 57

def initialize
  @abort_on_exception = false
  @join = true
  @threads = 8
end

Class Method Details

.dsl_accessor(*symbols) ⇒ Object

Allow for for an easy way to add dsl words that are simply setters.

class PartyProxyChild < PartyProxy

dsl_accessor :set_this

end

PartyProxyChild do

set_this value

end

This also defines get_#symbol to allow for “normal” access to the variable outside of dsl context.



19
20
21
22
23
24
25
26
# File 'lib/threadparty/partyproxy.rb', line 19

def self.dsl_accessor(*symbols)
  symbols.each do |symbol|
    instance_symbol = "@#{symbol}".to_sym
    define_method(symbol) do |value|
      instance_variable_set(instance_symbol, value)
    end
  end
end

.dsl_method(*symbols) ⇒ Object

Allow for for an easy way to add dsl methods that are blocks.

class PartyProxyChild < PartyProxy

dsl_method :do_this

end

PartyProxyChild do

collection ["left", "right"]
do_this {|hand| puts "your #{hand} in!"}

end



46
47
48
49
50
51
52
53
# File 'lib/threadparty/partyproxy.rb', line 46

def self.dsl_method(*symbols)
  symbols.each do |symbol|
    instance_symbol = "@#{symbol}".to_sym
    define_method symbol do |&block|
      instance_variable_set instance_symbol, block
    end
  end
end

.is_proxyObject

Method that is a nice way to say that I’m going to be a proxy.



31
32
33
# File 'lib/threadparty/partyproxy.rb', line 31

def self.is_proxy
  ThreadPartyProxy.add_proxy_reciever self
end

Instance Method Details

#executeObject

Execute should return the results of each thread’s to-do.



78
79
# File 'lib/threadparty/partyproxy.rb', line 78

def execute
end

#threadedObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/threadparty/partyproxy.rb', line 64

def threaded
  threads = (0...@threads).collect do |number|
    Thread.new do
      Thread.current.abort_on_exception = @abort_on_exception
      begin
        yield number
      rescue ThreadError
      end
    end
  end
  threads.each(&:join) if @join
end