100% yardoc

Files:          16
Modules:         5 (    0 undocumented)
Classes:        11 (    0 undocumented)
Constants:      20 (    0 undocumented)
Methods:       136 (    0 undocumented)
 100.00% documented
This commit is contained in:
Michael Kessler 2011-09-20 15:07:29 +02:00
parent b944932f53
commit c0dcef9dbc
4 changed files with 103 additions and 56 deletions

View File

@ -1,3 +1,6 @@
# Guard is the main module for all Guard related modules and classes.
# Also other Guard implementation should use this namespace.
#
module Guard
autoload :UI, 'guard/ui'

View File

@ -11,8 +11,11 @@ module Guard
# The Listener is the base class for all listener
# implementations.
#
# @abstract
#
class Listener
# Default paths that gets ignored by the listener
DEFAULT_IGNORE_PATHS = %w[. .. .bundle .git log tmp vendor]
attr_accessor :changed_files
@ -44,7 +47,7 @@ module Guard
# @option options [Boolean] relativize_paths use only relative paths
# @option options [Array<String>] ignore_paths the paths to ignore by the listener
#
def initialize(directory = Dir.pwd, options = { })
def initialize(directory = Dir.pwd, options = {})
@directory = directory.to_s
@sha1_checksums_hash = { }
@relativize_paths = options.fetch(:relativize_paths, true)
@ -118,7 +121,12 @@ module Guard
@last_event = Time.now
end
def modified_files(dirs, options = { })
# Get the modified files.
#
# @param [Array<String>] dirs the watched directories
# @param [Hash] options the listener options
#
def modified_files(dirs, options = {})
last_event = @last_event
update_last_event
files = potentially_modified_files(dirs, options).select { |path| file_modified?(path, last_event) }

View File

@ -3,27 +3,6 @@ module Guard
# The UI class helps to format messages for the user.
#
module UI
ANSI_ESCAPE_BRIGHT = "1"
ANSI_ESCAPE_BLACK = "30"
ANSI_ESCAPE_RED = "31"
ANSI_ESCAPE_GREEN = "32"
ANSI_ESCAPE_YELLOW = "33"
ANSI_ESCAPE_BLUE = "34"
ANSI_ESCAPE_MAGENTA = "35"
ANSI_ESCAPE_CYAN = "36"
ANSI_ESCAPE_WHITE = "37"
ANSI_ESCAPE_BGBLACK = "40"
ANSI_ESCAPE_BGRED = "41"
ANSI_ESCAPE_BGGREEN = "42"
ANSI_ESCAPE_BGYELLOW = "43"
ANSI_ESCAPE_BGBLUE = "44"
ANSI_ESCAPE_BGMAGENTA = "45"
ANSI_ESCAPE_BGCYAN = "46"
ANSI_ESCAPE_BGWHITE = "47"
class << self
color_enabled = nil
@ -34,8 +13,8 @@ module Guard
# @param [Hash] options the options
# @option options [Boolean] reset whether to clean the output before
#
def info(message, options = {})
unless ENV["GUARD_ENV"] == "test"
def info(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
puts color(message) if message != ''
end
@ -47,8 +26,8 @@ module Guard
# @param [Hash] options the options
# @option options [Boolean] reset whether to clean the output before
#
def error(message, options = {})
unless ENV["GUARD_ENV"] == "test"
def error(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
puts color('ERROR: ', :red) + message
end
@ -60,8 +39,8 @@ module Guard
# @param [Hash] options the options
# @option options [Boolean] reset whether to clean the output before
#
def deprecation(message, options = {})
unless ENV["GUARD_ENV"] == "test"
def deprecation(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
puts color('DEPRECATION: ', :red) + message
end
@ -74,7 +53,7 @@ module Guard
# @option options [Boolean] reset whether to clean the output before
#
def debug(message, options={ })
unless ENV["GUARD_ENV"] == "test"
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
puts color("DEBUG (#{Time.now.strftime('%T')}): ", :yellow) + message if ::Guard.options && ::Guard.options[:debug]
end
@ -89,7 +68,7 @@ module Guard
# Clear the output.
#
def clear
system("clear;")
system('clear;')
end
private
@ -100,30 +79,8 @@ module Guard
# @param [String] text the text
#
def reset_color(text)
deprecation('UI.reset_color(text) is deprecated, please use color(text, "") instead.')
color(text, "")
end
# Colorizes a text message.
#
# @example
# color("Hello World", :red, :bright)
#
# @param [String] the text to colorize
# @param [Array] color_options
#
def color(text, *color_options)
color_code = ""
color_options.each do |color_option|
color_option = color_option.to_s
if color_option != ""
if !(color_option =~ /\d+/)
color_option = const_get("ANSI_ESCAPE_#{ color_option.upcase }")
end
color_code += ";" + color_option
end
end
color_enabled? ? "\e[0#{ color_code }m#{ text }\e[0m" : text
deprecation('UI.reset_color(text) is deprecated, please use color(text, ' ') instead.')
color(text, '')
end
# Checks if color output can be enabled.
@ -153,6 +110,82 @@ module Guard
@color_enabled
end
# Colorizes a text message. See the constant below for possible
# color_options parameters. You can pass :bright, a foreground
# and a background color.
#
# @example
# color('Hello World', :red, :bright)
#
# @param [String] the text to colorize
# @param [Array] color_options the color options
#
def color(text, *color_options)
color_code = ''
color_options.each do |color_option|
color_option = color_option.to_s
if color_option != ''
if !(color_option =~ /\d+/)
color_option = const_get("ANSI_ESCAPE_#{ color_option.upcase }")
end
color_code += ';' + color_option
end
end
color_enabled? ? "\e[0#{ color_code }m#{ text }\e[0m" : text
end
end
# bright color
ANSI_ESCAPE_BRIGHT = '1'
# black foreground color
ANSI_ESCAPE_BLACK = '30'
# red foreground color
ANSI_ESCAPE_RED = '31'
# green foreground color
ANSI_ESCAPE_GREEN = '32'
# yellow foreground color
ANSI_ESCAPE_YELLOW = '33'
# blue foreground color
ANSI_ESCAPE_BLUE = '34'
# magenta foreground color
ANSI_ESCAPE_MAGENTA = '35'
# cyan foreground color
ANSI_ESCAPE_CYAN = '36'
# white foreground color
ANSI_ESCAPE_WHITE = '37'
# black background color
ANSI_ESCAPE_BGBLACK = '40'
# red background color
ANSI_ESCAPE_BGRED = '41'
# green background color
ANSI_ESCAPE_BGGREEN = '42'
# yellow background color
ANSI_ESCAPE_BGYELLOW = '43'
# blue background color
ANSI_ESCAPE_BGBLUE = '44'
# magenta background color
ANSI_ESCAPE_BGMAGENTA = '45'
# cyan background color
ANSI_ESCAPE_BGCYAN = '46'
# white background color
ANSI_ESCAPE_BGWHITE = '47'
end
end

View File

@ -1,3 +1,6 @@
module Guard
VERSION = "0.7.0" unless defined? Guard::VERSION
unless defined? Guard::VERSION
# The current gem version of Guard
VERSION = '0.7.0'
end
end