class Notiffany::Notifier::Base

Constants

ERROR_ADD_GEM_AND_RUN_BUNDLE
HOSTS

Attributes

options[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/notiffany/notifier/base.rb, line 47
def initialize(opts = {})
  options = opts.dup
  options.delete(:silent)
  @options =
    { title: "Notiffany" }.
    merge(self.class.const_get(:DEFAULTS)).
    merge(options).freeze

  @images_path = Pathname.new(__FILE__).dirname + "../../../images"

  _check_host_supported
  _require_gem
  _check_available(@options)
end

Public Instance Methods

_image_path(image) click to toggle source
# File lib/notiffany/notifier/base.rb, line 75
def _image_path(image)
  images = [:failed, :pending, :success, :guard]
  images.include?(image) ? @images_path.join("#{image}.png").to_s : image
end
name() click to toggle source
# File lib/notiffany/notifier/base.rb, line 66
def name
  title.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end
notify(message, opts = {}) click to toggle source
# File lib/notiffany/notifier/base.rb, line 70
def notify(message, opts = {})
  new_opts = _notify_options(opts).freeze
  _perform_notify(message, new_opts)
end
title() click to toggle source
# File lib/notiffany/notifier/base.rb, line 62
def title
  self.class.to_s[/.+::(\w+)$/, 1]
end

Private Instance Methods

_check_available(_options) click to toggle source

Override

# File lib/notiffany/notifier/base.rb, line 93
def _check_available(_options)
  fail NotImplementedError
end
_check_host_supported() click to toggle source
# File lib/notiffany/notifier/base.rb, line 114
def _check_host_supported
  return if _supported_hosts == :all
  expr = /#{_supported_hosts * '|'}/
  fail UnsupportedPlatform unless expr.match(RbConfig::CONFIG["host_os"])
end
_gem_name() click to toggle source

Override if necessary

# File lib/notiffany/notifier/base.rb, line 83
def _gem_name
  name
end
_notification_type(image) click to toggle source
# File lib/notiffany/notifier/base.rb, line 102
def _notification_type(image)
  [:failed, :pending, :success].include?(image) ? image : :notify
end
_notify_options(overrides = {}) click to toggle source
# File lib/notiffany/notifier/base.rb, line 106
def _notify_options(overrides = {})
  opts = @options.merge(overrides)
  img_type = opts.fetch(:image, :success)
  opts[:type] ||= _notification_type(img_type)
  opts[:image] = _image_path(img_type)
  opts
end
_perform_notify(_message, _opts) click to toggle source

Override

# File lib/notiffany/notifier/base.rb, line 98
def _perform_notify(_message, _opts)
  fail NotImplementedError
end
_require_gem() click to toggle source
# File lib/notiffany/notifier/base.rb, line 120
def _require_gem
  Kernel.require _gem_name unless _gem_name.nil?
rescue LoadError, NameError
  fail RequireFailed, _gem_name
end
_supported_hosts() click to toggle source

Override if necessary

# File lib/notiffany/notifier/base.rb, line 88
def _supported_hosts
  :all
end