Parent

Class/Module Index [+]

Quicksearch

Nanoc::CLI::Commands::Watch::Notifier

Allows sending user notifications in a cross-platform way.

Constants

TOOLS

A list of commandline tool names that can be used to send notifications

Public Instance Methods

notify(message) click to toggle source

Send a notification. If no notifier is found, no notification will be created.

@param [String] message The message to include in the notification

# File lib/nanoc/cli/commands/watch.rb, line 107
def notify(message)
  return if tool.nil?
  if tool == 'growlnotify' && self.on_windows?
    growlnotify_windows(message)
  else
    send(tool.tr('-', '_'), message)
  end
end

Protected Instance Methods

growlnotify(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 155
def growlnotify(message)
  system(*growlnotify_cmd_for(message))
end
growlnotify_cmd_for(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 151
def growlnotify_cmd_for(message)
  [ 'growlnotify', '-m', message ]
end
growlnotify_windows(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 163
def growlnotify_windows(message)
  system(*growlnotify_windows_cmd_for(message))
end
growlnotify_windows_cmd_for(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 159
def growlnotify_windows_cmd_for(message)
  [ 'growlnotify', '/t:nanoc', message ]
end
have_tool?(tool) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 130
def have_tool?(tool)
  if self.on_windows?
    self.have_tool_windows?(tool)
  else
    self.have_tool_nix?(tool)
  end
end
have_tool_nix?(tool) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 118
def have_tool_nix?(tool)
  !`which #{tool}`.empty?
rescue Errno::ENOENT
  false
end
have_tool_windows?(tool) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 124
def have_tool_windows?(tool)
  !`where #{tool} 2> nul`.empty?
rescue Errno::ENOENT
  false
end
notify_send(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 167
def notify_send(message)
  system('notify-send', message)
end
on_windows?() click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 171
def on_windows?
  Nanoc.on_windows?
end
terminal_notify(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 147
def terminal_notify(message)
  TerminalNotifier.notify(message, :title => 'nanoc')
end
tool() click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 138
def tool
  @tool ||= begin
    require 'terminal-notifier'
    'terminal-notify'
  rescue LoadError
    TOOLS.find { |t| have_tool?(t) }
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.