class Bolt::Base

Public Class Methods

new() click to toggle source
# File lib/bolt/base.rb, line 18
def initialize
  STDOUT.sync = true
end

Public Instance Methods

create_directory(directory, options = {}) click to toggle source

Creates a directory, prefixes $config.base_dir if required

# File lib/bolt/base.rb, line 23
def create_directory(directory, options = {})
  options[:error_if_exists] = (options[:error_if_exists].nil?) ? true : options[:error_if_exists]
  directory = d(directory) if options[:base_dir].nil?
  
  if File.directory?(directory)
    raise ArgumentError, "#{directory} exists already." if options[:error_if_exists]
  else
    Dir.mkdir(directory)
    puts "Created #{directory}"
  end            
end
create_file(file, options = {}) click to toggle source

Creates a file, file, with the contents of :copy_from, prefixes $config.base_dir

# File lib/bolt/base.rb, line 43
def create_file(file, options = {})
  file = d(file)
        
  options[:mode] ||= "r"
  options[:copy_from] ||= false
  
  if options[:copy_from]          
    f = FileUtils.copy(options[:copy_from], file)
  else
    f = File.new(file, options[:mode])
  end

  puts "Created #{file}"
end
d(file_or_directory) click to toggle source

Returns file_or_directory with $config.base_dir prefixed

# File lib/bolt/base.rb, line 64
def d(file_or_directory)
  $config.base_dir + file_or_directory
end
open_file(file, mode = "r") click to toggle source

Opens file, file with mode, mode prefixes $config.base_dir

# File lib/bolt/base.rb, line 59
def open_file(file, mode = "r")
  File.open(d(file), mode)
end
remove_directory(directory) click to toggle source

Forces removal of directory, directory

# File lib/bolt/base.rb, line 36
def remove_directory(directory)
  directory = d(directory)
  FileUtils.rm_rf(directory)
  puts "Removed #{directory}"
end