Sha256: 76f235908fc98e754f68be20f456410fd0b355fd397d2b95a398d6bee507ea22
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
module Travis module Notifications autoload :Email, 'travis/notifications/email' autoload :Irc, 'travis/notifications/irc' autoload :Pusher, 'travis/notifications/pusher' autoload :Webhook, 'travis/notifications/webhook' autoload :Worker, 'travis/notifications/worker' class << self include Logging def subscriptions @subscriptions ||= Array(Travis.config.notifications).inject({}) do |subscriptions, subscriber| subscriber = const_get(subscriber.to_s.camelize) subscriptions.merge(subscriber.new => subscriber::EVENTS) end end def dispatch(event, *args) subscriptions.each do |subscriber, subscription| if matches?(subscription, event) log "notifying #{subscriber.class.name} about #{event.inspect} (#{args.map { |arg| arg.inspect }.join(', ')})" subscriber.notify(event, *args) end end end protected def matches?(subscription, event) Array(subscription).any? do |subscription| subscription.is_a?(Regexp) ? subscription.match(event) : subscription == event end end end def notify(event, *args) Travis::Notifications.dispatch(client_event(event, self), self, *args) end protected def client_event(event, object) event = "#{event}ed".gsub('eed', 'ed') unless event == :log namespace = object.class.name.underscore.gsub('/', ':').gsub('travis:model:', '') [namespace, event].join(':') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
travis-core-0.0.1 | lib/travis/notifications.rb |