Module: State::Notifier

Extended by:
ActiveSupport::Concern
Defined in:
lib/state/notifier.rb,
lib/state/notifier/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.0.8"

Instance Method Summary collapse

Instance Method Details

#notify_targets(event) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/state/notifier.rb', line 7

def notify_targets(event)
  name = self.class.name.underscore
  method = [name, event] * '_'

  targets = self.class.notification_targets.map do |m|
    m.is_a?(Symbol) ? send(m) : m
  end.flatten
  Rails.logger.debug "StateNotifier: notifying #{method}, #{targets.size} targets"

  targets.each do |t|
    t.send(method, self) if t.respond_to?(method)
  end
end

#notify_transition(transition) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/state/notifier.rb', line 21

def notify_transition(transition)
  notify_targets transition.event
  unless transition.to == transition.from
    notify_targets transition.to
    notify_targets "#{transition.from}_#{transition.event}"
    notify_targets "#{transition.event}_#{transition.to}"
    notify_targets "#{transition.from}_#{transition.to}"
    notify_targets "#{transition.from}_#{transition.event}_#{transition.to}"
    notify_targets :state_changed
  end
end