class DropboxDotfiles

Public Class Methods

configuration(&block) click to toggle source
# File bin/dropbox-dotfiles, line 163
def DropboxDotfiles.configuration(&block)
  dropbox = File.expand_path File.join $my_dropbox_directory, 'Dotfiles'
  home = File.expand_path '~'

  dp = DropboxDotfiles.new(dropbox, home, Stats.new)
  dp.instance_eval &block
  dp.report
end
new(dropbox, home, stats) click to toggle source
# File bin/dropbox-dotfiles, line 153
def initialize(dropbox, home, stats)
  @stats = stats

  create_dir_if_doesnt_exists dropbox
  @dropbox = dropbox

  create_dir_if_doesnt_exists home
  @home = home
end

Public Instance Methods

cd(dir, &block) click to toggle source
# File bin/dropbox-dotfiles, line 186
def cd(dir, &block)
  dropbox = File.join @dropbox, dir
  home = File.join @home, dir
  DropboxDotfiles.new(dropbox, home, @stats).instance_eval &block
end
dir(name) click to toggle source
# File bin/dropbox-dotfiles, line 192
def dir(name)
  create_link name, :directory?
end
file(name) click to toggle source
# File bin/dropbox-dotfiles, line 182
def file(name)
  create_link name, :file?
end
report() click to toggle source
# File bin/dropbox-dotfiles, line 172
def report
  if @stats.correct_links == 0 and @stats.links_created == 0 and @stats.errors == 0
    puts 'Your configuration file is empty!'
  else
    puts "#{@stats.correct_links} link were already present and correct"
    puts "#{@stats.links_created} new links were created" if @stats.links_created > 0
    puts "#{@stats.errors} errors" if @stats.errors > 0
  end
end

Private Instance Methods

create_dir_if_doesnt_exists(dir) click to toggle source
# File bin/dropbox-dotfiles, line 197
def create_dir_if_doesnt_exists(dir)
  unless File.directory? dir
    if File.exists? dir
      error "'#{dir}' is not a directory!"
      exit!
    else
      begin
        Dir.mkdir dir
      rescue Exception => e
        error "#{e.message}"
        exit!
      end
    end
  end
end