Class: Safeguard::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/safeguard/worker.rb

Overview

Something that works behind the scenes, possibly talking to an user interface in the middle of it through callbacks.

Direct Known Subclasses

Hasher, Verifier

Class Method Summary collapse

Class Method Details

.callbacksObject

All callbacks defined for this class.



12
13
14
# File 'lib/safeguard/worker.rb', line 12

def callbacks
  @callbacks ||= []
end

.has_callback(*names) ⇒ Object Also known as: has_callbacks

Defines callbacks for this class.



17
18
19
20
21
22
23
24
25
# File 'lib/safeguard/worker.rb', line 17

def has_callback(*names)
  callbacks.push *names
  names.map(&:to_sym).each do |callback|
    iv_name = callback.to_s.prepend('@').to_sym
    define_method callback do |&block|
      assign_callback iv_name, &block
    end
  end
end