class Rubtools::Recipe

Attributes

available_methods[RW]
config[RW]
methods_hidden[RW]
options[RW]

Public Class Methods

are_methods_hidden?() click to toggle source
# File lib/rubtools/recipe.rb, line 20
def self.are_methods_hidden?
  @methods_hidden
end
available_methods() click to toggle source
# File lib/rubtools/recipe.rb, line 12
def self.available_methods
  @available_methods ? @available_methods : []
end
hide_methods() click to toggle source
# File lib/rubtools/recipe.rb, line 16
def self.hide_methods
  @methods_hidden = true
end
new(config, options, *args, &blk) click to toggle source

Override new method to initialize recipes objects without config and options

# File lib/rubtools/recipe.rb, line 26
def self.new config, options, *args, &blk
  object = allocate
  object.config = config
  object.options = options
  object.instance_eval { initialize( *args, &blk ) }
  object
end
register_methods(methods) click to toggle source
# File lib/rubtools/recipe.rb, line 8
def self.register_methods methods
  @available_methods = methods
end

Public Instance Methods

error(args) click to toggle source

Print errors arguments

# File lib/rubtools/recipe.rb, line 126
def error args
  Logger.error args
end
exec(cmd, &block) click to toggle source

Exec with output

# File lib/rubtools/recipe.rb, line 54
def exec cmd, &block
  success "$ " + cmd if @options[:verbose]

  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
    while line = stdout.gets
      verbose line
    end

    exit_status = wait_thr.value

    if block
      block.call exit_status
    end

    return stdout
  end

  return nil
end
exec_without_output(cmd, &block) click to toggle source

Exec without output

# File lib/rubtools/recipe.rb, line 36
def exec_without_output cmd, &block
  success "$ " + cmd if @options[:verbose]

  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
    exit_status = wait_thr.value

    if block
      block.call exit_status
    end

    return stdout
  end

  return nil
end
info(args) click to toggle source

Print info arguments

# File lib/rubtools/recipe.rb, line 138
def info args
  Logger.info args
end
os() click to toggle source

Get operating system name

# File lib/rubtools/recipe.rb, line 76
def os
  return (
    host_os = RbConfig::CONFIG['host_os']
    case host_os
    when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
      :windows
    when /darwin|mac os/
      :osx
    when /linux/
      :linux
    when /solaris|bsd/
      :unix
    else
      raise "Unknown os: #{host_os.inspect}"
    end
  )
end
success(args) click to toggle source

Print success arguments

# File lib/rubtools/recipe.rb, line 120
def success args
  Logger.success args
end
verbose(args) click to toggle source

Print verbose arguments

# File lib/rubtools/recipe.rb, line 132
def verbose args
  Logger.verbose args
end
which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH.

# File lib/rubtools/recipe.rb, line 96
def which cmd
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable? exe
    end
  end
  return nil
end