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 106
def notify(message)
  return if tool.nil?
  if tool == 'growlnotify' && self.on_windows?
    self.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 154
def growlnotify(message)
  system(*self.growlnotify_cmd_for(message))
end
growlnotify_cmd_for(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 150
def growlnotify_cmd_for(message)
  [ 'growlnotify', '-m', message ]
end
growlnotify_windows(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 162
def growlnotify_windows(message)
  system(*self.growlnotify_windows_cmd_for(message))
end
growlnotify_windows_cmd_for(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 158
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 129
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 117
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 123
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 166
def notify_send(message)
  system('notify-send', message)
end
on_windows?() click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 170
def on_windows?
  !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/)
end
terminal_notify(message) click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 146
def terminal_notify(message)
  TerminalNotifier.notify(message, :title => "nanoc")
end
tool() click to toggle source
# File lib/nanoc/cli/commands/watch.rb, line 137
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.