class Notiffany::Notifier::Base
Constants
- ERROR_ADD_GEM_AND_RUN_BUNDLE
- HOSTS
Attributes
Public Class Methods
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
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
Source
# File lib/notiffany/notifier/base.rb, line 66 def name title.gsub(/([a-z])([A-Z])/, '\1_\2').downcase end
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
Source
# File lib/notiffany/notifier/base.rb, line 62 def title self.class.to_s[/.+::(\w+)$/, 1] end
Private Instance Methods
Source
# File lib/notiffany/notifier/base.rb, line 93 def _check_available(_options) fail NotImplementedError end
Override
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
Source
# File lib/notiffany/notifier/base.rb, line 83 def _gem_name name end
Override if necessary
Source
# File lib/notiffany/notifier/base.rb, line 102 def _notification_type(image) [:failed, :pending, :success].include?(image) ? image : :notify end
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
Source
# File lib/notiffany/notifier/base.rb, line 98 def _perform_notify(_message, _opts) fail NotImplementedError end
Override
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
Source
# File lib/notiffany/notifier/base.rb, line 88 def _supported_hosts :all end
Override if necessary