Class: Guard::Notifier::FileNotifier

Inherits:
Base
  • Object
show all
Defined in:
lib/guard/notifiers/file_notifier.rb

Overview

Writes Guard notification results to a file.

Examples:

Add the `:file` notifier to your `Guardfile`

notification :file, path: 'tmp/guard_result'

Constant Summary

DEFAULTS =
{
  format: "%s\n%s\n%s\n"
}

Constants inherited from Base

Base::HOSTS

Instance Attribute Summary

Attributes inherited from Base

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

_supported_host?, gem_name, #images_path, #initialize, name, #name, #normalize_standard_options!, require_gem_safely, supported_hosts, title, #title

Constructor Details

This class inherits a constructor from Guard::Notifier::Base

Class Method Details

.available?(opts = {}) ⇒ Boolean

Parameters:

  • opts (Hash) (defaults to: {})

    some options

Options Hash (opts):

  • path (Boolean)

    the path to a file where Guard notification results will be written

Returns:

  • (Boolean)


21
22
23
# File 'lib/guard/notifiers/file_notifier.rb', line 21

def self.available?(opts = {})
  super and opts.has_key?(:path)
end

Instance Method Details

#notify(message, opts = {}) ⇒ Object

Writes the notification to a file. By default it writes type, title, and message separated by newlines.

Parameters:

  • message (String)

    the notification message body

  • opts (Hash) (defaults to: {})

    additional notification library options

Options Hash (opts):

  • type (String)

    the notification type. Either 'success', 'pending', 'failed' or 'notify'

  • title (String)

    the notification title

  • image (String)

    the path to the notification image

  • format (String)

    printf style format for file contents

  • path (String)

    the path of where to write the file



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/guard/notifiers/file_notifier.rb', line 37

def notify(message, opts = {})
  super

  if opts[:path]
    format = opts.fetch(:format, DEFAULTS[:format])

    _write(opts[:path], format % [opts[:type], opts[:title], message])
  else
    ::Guard::UI.error ':file notifier requires a :path option'
  end
end