-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/pr/407'
Conflicts: CHANGELOG.md
- Loading branch information
Showing
6 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
module Guard | |||
module Notifier | |||
|
|||
# Writes guard notification results to a file | |||
# | |||
# @example Add the `:file` notifier to your `Guardfile` | |||
# notification :file, path: 'tmp/guard_result' | |||
# | |||
module FileNotifier | |||
extend self | |||
|
|||
# Default options for FileNotifier | |||
DEFAULTS = { | |||
:format => "%s\n%s\n%s\n" | |||
} | |||
|
|||
# Test if the file notification option is available? | |||
# | |||
# REVIEW: This could test if there is a path provided in options, but | |||
# we don't get options in available?. | |||
# | |||
# @param [Boolean] silent true if no error messages should be shown | |||
# @return [Boolean] the availability status | |||
# | |||
def available?(silent = false) | |||
true | |||
end | |||
|
|||
# Write the notification to a file. By default it writes type, tytle, and | |||
# message separated by newlines. | |||
# | |||
# @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify' | |||
# @param [String] title the notification title | |||
# @param [String] message the notification message body | |||
# @param [String] image the path to the notification image | |||
# @param [Hash] options additional notification library options | |||
# @option options [String] format printf style format for file contents | |||
# @option options [String] path the path of where to write the file | |||
# | |||
def notify(type, title, message, image, options = { }) | |||
if options[:path] | |||
format = options.fetch(:format, DEFAULTS[:format]) | |||
|
|||
write(options[:path], format % [type, title, message]) | |||
end | |||
end | |||
|
|||
private | |||
def write(path, contents) | |||
File.write(path, contents) | |||
end | |||
end | |||
|
|||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
require 'spec_helper' | |||
|
|||
|
|||
describe Guard::Notifier::FileNotifier do | |||
|
|||
describe '.available?' do | |||
it 'is always true' do | |||
subject.should be_available | |||
end | |||
end | |||
|
|||
describe '.notify' do | |||
it 'writes to a file on success' do | |||
subject.should_receive(:write).with('tmp/guard_result', "success\nany title\nany message\n") | |||
|
|||
subject.notify('success', 'any title', 'any message', 'any image', { :path => 'tmp/guard_result' }) | |||
end | |||
|
|||
it 'also writes to a file on failure' do | |||
subject.should_receive(:write).with('tmp/guard_result', "failed\nany title\nany message\n") | |||
|
|||
subject.notify('failed', 'any title', 'any message', 'any image', { :path => 'tmp/guard_result' }) | |||
end | |||
|
|||
# We don't have a way to return false in .available? when no path is | |||
# specified. So, we just don't do anything in .notify if there's no path. | |||
it 'does not write to a file if no path is specified' do | |||
subject.should_not_receive(:write) | |||
|
|||
subject.notify('success', 'any title', 'any message', 'any image', { }) | |||
end | |||
end | |||
end |