Parent

Files

Guard::Notifier::Base

Base class for all notifiers.

Constants

HOSTS

Attributes

options[R]

Public Class Methods

_supported_host?() click to toggle source

@private

Checks if the current OS is supported by the notifier.

@see .supported_hosts

# File lib/guard/notifiers/base.rb, line 157
def self._supported_host?
  supported_hosts == :all ||
  RbConfig::CONFIG['host_os'] =~ /#{supported_hosts.join('|')}/
end
available?(opts = {}) click to toggle source

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 = {})
  options = { silent: false }.merge(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 options[:silent]
    return false
  end

  true
end
gem_name() click to toggle source

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 96
def self.gem_name
  name
end
name() click to toggle source

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 83
def self.name
  title.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end
new(opts = {}) click to toggle source
# File lib/guard/notifiers/base.rb, line 25
def initialize(opts = {})
  @options = opts
end
require_gem_safely(opts = {}) click to toggle source

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 109
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
supported_hosts() click to toggle source

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
title() click to toggle source

Returns the title of the notifier.

@example Un-modulize the class name

Guard::Notifier::FileNotifier.title
#=> 'FileNotifier'

@return [String] the title of the notifier

# File lib/guard/notifiers/base.rb, line 71
def self.title
  self.to_s.sub(/.+::(\w+)$/, '\1')
end

Public Instance Methods

images_path() click to toggle source

Paths where all Guard images are located

@return [Pathname] the path to the images directory

# File lib/guard/notifiers/base.rb, line 147
def images_path
  @images_path ||= Pathname.new(File.dirname(__FILE__)).join('../../../images')
end
name() click to toggle source

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 139
def name
  self.class.name
end
normalize_standard_options!(opts) click to toggle source

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 171
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
notify(message, opts = {}) click to toggle source

This method must be implemented.

# File lib/guard/notifiers/base.rb, line 59
def notify(message, opts = {})
  raise NotImplementedError
end
title() click to toggle source

Returns the title of the notifier.

@example Un-modulize the class name

Guard::Notifier::FileNotifier.new.title
#=> 'FileNotifier'

@return [String] the title of the notifier

# File lib/guard/notifiers/base.rb, line 127
def title
  self.class.title
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.