class Dream::Mind

Public Instance Methods

sleep() click to toggle source
# File lib/dream/cli.rb, line 10
def sleep()
  install('dream.yml')
end

Private Instance Methods

install(template_file) click to toggle source
# File lib/dream/cli.rb, line 14
def install(template_file)
  install_path = options[:install] ? options[:install] : '.'
  filename = options[:name] ? options[:name] : template_file
  template = File.read(File.join(File.dirname(__FILE__),'templates',template_file))
  success = false
  msg = ''
  file = File.join(install_path, filename)
  if File.exists?(file)
    warn "[skip] `#{filename}' already exists"
    if yes?("Would you like to overwrite the existing file?")
      msg = "#{filename} has been overwritten"
      success=true
    end
  elsif File.exists?(file.downcase)
    warn "[skip] `#{filename.downcase}' exists, which could conflict with `#{filename}'"
    if yes?("Would you like to overwrite the existing file?")
      msg = "#{filename} has been overwritten"
      success=true
    end
  elsif !File.exists?(File.dirname(file))
    warn "[skip] directory `#{File.dirname(file)}' does not exist"
    if yes?("Would you like to make the directory?")
      FileUtils.mkdir_p(install_path)
      msg = "The directory #{install_path} was created"
      success=true
    end
  else
    msg = "There were no issues with the installation"
    success=true
  end

  if success
    puts "[add] writing `#{filename}'"
    File.open(file, "w") { |f| f.write(template) }
    puts "#{msg}"
    puts "[done] Dream was successfully installed. Sleep well."
  else
    puts "[error] Dream was not successfully installed."
  end
end