Sha256: 2b2fb49f003f96563d13fd29762733cf80af58e1e5867f70f4ce4ed74332496e

Contents?: true

Size: 981 Bytes

Versions: 6

Compression:

Stored size: 981 Bytes

Contents

# Notifies you about failures and errors in your riot tests!
#
# Usage:
#   require 'riot'
#   require 'riot_notifier'
#
#   # auto-detection
#   Riot.reporter = RiotNotifier
#   # try these first
#   Riot.reporter = RiotNotifier[:RedgreenBinary, :Libnotify]
#
module RiotNotifier

  def self.new(*args, &block)
    notifier_class = notifier_classes.detect(&:usable?) || None
    notifier_class.new(*args, &block)
  end

  def self.register(notifier)
    order.unshift notifier
  end

  def self.unregister(notifier)
    order.delete notifier
  end

  def self.unregister_all
    order.clear
  end

  def self.order
    @order ||= []
  end

  def self.try(*order)
    @order = order
    self
  end

  class << self
    alias [] try
  end

  def self.notifier_classes
    order.map { |o| resolve_notifier_class(o) }.compact - [None]
  end

  def self.resolve_notifier_class(o)
    case o
    when Class; o
    when Symbol, String; const_get(o)
    else
      nil
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
riot_notifier-0.5.0 lib/riot_notifier/module.rb
riot_notifier-0.4.0 lib/riot_notifier/module.rb
riot_notifier-0.3.0 lib/riot_notifier/module.rb
riot_notifier-0.2.0 lib/riot_notifier/module.rb
riot_notifier-0.1.1 lib/riot_notifier/module.rb
riot_notifier-0.0.8 lib/riot_notifier/module.rb