Object
Base class for all notifiers.
@private
Checks if the current OS is supported by the notifier.
@see .supported_hosts
# File lib/guard/notifiers/base.rb, line 156 def self._supported_host? supported_hosts == :all || RbConfig::CONFIG['host_os'] =~ /#{supported_hosts.join('|')}/ end
Test if the notifier can be used.
@param [Hash] opts notifier options @option opts [Boolean] silent true if no error messages should be shown @return [Boolean] the availability status
# File lib/guard/notifiers/base.rb, line 45 def self.available?(opts = {}) unless _supported_host? hosts = supported_hosts.map { |host| HOSTS[host.to_sym] }.join(', ') ::Guard::UI.error "The :#{name} notifier runs only on #{hosts}." unless opts.fetch(:silent) { false } return false end true end
Returns the name of the notifier's gem. By default it returns the notifier name. This method can be overriden by subclasses.
@example Un-modulize, underscorize and downcase the class name
Guard::Notifier::FileNotifier.gem_name #=> 'file_notifier'
@return [String] the name of the notifier's gem
# File lib/guard/notifiers/base.rb, line 95 def self.gem_name name end
Returns the name of the notifier.
@example Un-modulize, underscorize and downcase the class name
Guard::Notifier::FileNotifier.name #=> 'file_notifier'
@return [String] the name of the notifier
# File lib/guard/notifiers/base.rb, line 82 def self.name title.gsub(/([a-z])([A-Z])/, '\1_\2').downcase end
# File lib/guard/notifiers/base.rb, line 25 def initialize(opts = {}) @options = opts end
This method tries to require the gem whose name is returned by `.gem_name`. If a LoadError or NameError occurs, it displays an error message (unless opts is true) and returns false.
@param [Hash] opts some options @option opts [Boolean] silent true if no error messages should be shown
@return [Boolean] whether or not the gem is loaded
# File lib/guard/notifiers/base.rb, line 108 def self.require_gem_safely(opts = {}) require gem_name true rescue LoadError, NameError unless opts[:silent] ::Guard::UI.error "Please add \"gem '#{gem_name}'\" to your Gemfile and run Guard with \"bundle exec\"." end false end
This method should be overriden by subclasses and return an array of OSes the notifier supports. By default, it returns :all which mean there's no check against the current OS.
@see HOSTS for the list of possible OSes
# File lib/guard/notifiers/base.rb, line 35 def self.supported_hosts :all end
Paths where all Guard images are located
@return [Pathname] the path to the images directory
# File lib/guard/notifiers/base.rb, line 146 def images_path @images_path ||= Pathname.new(File.dirname(__FILE__)).join('../../../images') end
Returns the name of the notifier.
@example Un-modulize, underscorize and downcase the class name
Guard::Notifier::FileNotifier.new.name #=> 'file_notifier'
@return [String] the name of the notifier
# File lib/guard/notifiers/base.rb, line 138 def name self.class.name end
Set or modify the `:title`, `:type` and `:image` options for a notification. Should be used in `notify`.
@param [Hash] opts additional notification library options @option opts [String] type the notification type. Either 'success',
'pending', 'failed' or 'notify'
@option opts [String] title the notification title @option opts [String] image the path to the notification image
# File lib/guard/notifiers/base.rb, line 170 def normalize_standard_options!(opts) opts[:title] ||= 'Guard' opts[:type] ||= _notification_type(opts.fetch(:image, :success)) opts[:image] = _image_path(opts.delete(:image) { :success }) end
Generated with the Darkfish Rdoc Generator 2.