Class: Backups::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/backups/events.rb

Constant Summary collapse

@@events =
{}

Class Method Summary collapse

Class Method Details

.fire(event, params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/backups/events.rb', line 20

def self.fire event, params
  params[:event] = event
  names = []
  if event.kind_of? Array
    names = event
  else
    names << event
  end

  names.each do |name|
    if @@events.has_key? name
      @@events[name].each do |cb|
        res = cb.call(params)
        break if res == false
      end
    end
  end
end

.on(*events, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/backups/events.rb', line 6

def self.on *events, &block
  names = []
  if events.kind_of? Array
    names = events
  else
    names << events
  end

  names.each do |name|
    @@events[name] ||= []
    @@events[name] << block
  end
end