Class: Peon::Handler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Handler

Returns a new instance of Handler.



5
6
7
8
9
10
11
12
# File 'lib/peon/handler.rb', line 5

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

Instance Attribute Details

#onObject

Returns the value of attribute on.



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

def on
  @on
end

#queueObject

Returns the value of attribute queue.



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

def queue
  @queue
end

#subObject

Returns the value of attribute sub.



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

def sub
  @sub
end

#taskObject

Returns the value of attribute task.



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

def task
  @task
end

#unsubObject

Returns the value of attribute unsub.



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

def unsub
  @unsub
end

#whenObject

Returns the value of attribute when.



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

def when
  @when
end

Instance Method Details

#checkObject



18
19
20
21
22
23
24
25
26
# File 'lib/peon/handler.rb', line 18

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)


14
15
16
# File 'lib/peon/handler.rb', line 14

def should_sub?
  @when.call
end

#to_sObject



28
29
30
# File 'lib/peon/handler.rb', line 28

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