Class: Minion::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/minion/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Handler

Returns a new instance of Handler.



4
5
6
7
8
9
10
# File 'lib/minion/handler.rb', line 4

def initialize(queue)
	@queue = queue
	@when = lambda { true }
	@sub = lambda {}
	@unsub = lambda {}
	@on = false
end

Instance Attribute Details

#onObject

Returns the value of attribute on.



3
4
5
# File 'lib/minion/handler.rb', line 3

def on
  @on
end

#queueObject

Returns the value of attribute queue.



3
4
5
# File 'lib/minion/handler.rb', line 3

def queue
  @queue
end

#subObject

Returns the value of attribute sub.



3
4
5
# File 'lib/minion/handler.rb', line 3

def sub
  @sub
end

#unsubObject

Returns the value of attribute unsub.



3
4
5
# File 'lib/minion/handler.rb', line 3

def unsub
  @unsub
end

#whenObject

Returns the value of attribute when.



3
4
5
# File 'lib/minion/handler.rb', line 3

def when
  @when
end

Instance Method Details

#checkObject



16
17
18
19
20
21
22
23
24
# File 'lib/minion/handler.rb', line 16

def check
	if should_sub?
		@sub.call unless @on
		@on = true
	else
		@unsub.call if @on
		@on = false
	end
end

#should_sub?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/minion/handler.rb', line 12

def should_sub?
	@when.call
end

#to_sObject



26
27
28
# File 'lib/minion/handler.rb', line 26

def to_s
	"<handler queue=#{@queue} on=#{@on}>"
end