Module: Slatan::Ear

Defined in:
lib/slatan/ear.rb

Overview

class to Event Dispatching for concerns

Class Method Summary collapse

Class Method Details

.hear(msg) ⇒ Object

publish to subscribers



17
18
19
20
21
22
23
# File 'lib/slatan/ear.rb', line 17

def hear(msg)
  @concerns.each do |concern, block|
    if block.blank? || block.call(msg)
      concern.hear(msg)
    end
  end
end

.register(concern, &block) ⇒ Object

register subscriber

Parameters:

  • concern

    subscriber

  • block (option)

    condition for dispatching event



12
13
14
# File 'lib/slatan/ear.rb', line 12

def register(concern, &block)
  @concerns << [concern, block]
end