Permalink
Browse files

Allow different message formats per state

  • Loading branch information...
1 parent 5582390 commit 00826c40c0e1873a6e19ef712397e0cb3ad89862 @matthijsgroen matthijsgroen committed Oct 5, 2012
Showing with 9 additions and 4 deletions.
  1. +3 −3 lib/guard/notifiers/tmux.rb
  2. +6 −1 spec/guard/notifiers/tmux_spec.rb
@@ -21,7 +21,7 @@ module Tmux
:default => 'green',
:timeout => 5,
:display_message => false,
- :message_format => '%s - %s',
+ :default_message_format => '%s - %s',
:line_separator => ' - '
}
@@ -64,10 +64,10 @@ def notify(type, title, message, image, options = { })
# @param [String] message the notification message body
# @param [Hash] options additional notification library options
# @option options [Integer] timeout the amount of seconds to show the message in the statusbar (default is 5)
- # @option options [String] message_format a string to use as formatter. (default is '%s - %s')
+ # @option options [String] default_message_format a string to use as formatter. (default is '%s - %s')
# @option options [String] line_separator a string to use instead of a line-break. (default is ' - ')
def display_message(type, title, message, options = { })
- message_format = options[:message_format] || DEFAULTS[:message_format]
+ message_format = options["#{type}_message_format".to_sym] || options[:default_message_format] || DEFAULTS[:default_message_format]
display_time = options[:timeout] || DEFAULTS[:timeout]
separator = options[:line_separator] || DEFAULTS[:line_separator]
@@ -111,7 +111,12 @@ def self.show(options) end
it 'formats the message' do
subject.should_receive(:system).with('tmux display-message \'(any title) -> any message - line two\'').once
- subject.display_message 'success', 'any title', "any message\nline two", :message_format => '(%s) -> %s'
+ subject.display_message 'success', 'any title', "any message\nline two", :default_message_format => '(%s) -> %s'
+ end
+
+ it 'formats the message based on type' do
+ subject.should_receive(:system).with('tmux display-message \'[any title] => any message - line two\'').once
+ subject.display_message 'success', 'any title', "any message\nline two", :success_message_format => '[%s] => %s', :default_message_format => '(%s) -> %s'
end
it 'handles line-breaks' do

0 comments on commit 00826c4

Please sign in to comment.