class MacSetup::Symlink

Public Class Methods

new(options) click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 5
def initialize(options)
  @source_path = options[:source_path]
  @file_name = options[:name]
  @target_path = sanitize_target(options[:target_path])
end

Public Instance Methods

Private Instance Methods

children() click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 85
def children
  Dir.entries(source_path).reject { |entry| entry.start_with?(".") }
end
file_name() click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 46
def file_name
  @file_name ||= File.basename(source_path)
end
replace() click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 50
def replace
  if File.symlink?(target_path)
    replace_symlink
  elsif File.directory?(source_path)
    link_children
  else
    MacSetup.log "WARNING: File already exists at #{MacSetup.shorten_path(target_path)}. Skipping."
  end
end
sanitize_target(file) click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 89
def sanitize_target(file)
  Secrets.strip_extension(file)
end
source_exists() click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 25
def source_exists
  File.exist?(source_path).tap do |exists|
    unless exists
      short_source_path = MacSetup.shorten_path(source_path)
      MacSetup.log "WARNING: Source doesn’t exist at #{short_source_path}. Skipping."
    end
  end
end
source_path() click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 38
def source_path
  @source_path ||= File.expand_path(file_name, DOTFILES_PATH)
end
target_exists?() click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 34
def target_exists?
  File.exist?(target_path)
end
target_path() click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 42
def target_path
  @target_path ||= File.join(ENV["HOME"], ".#{sanitize_target(file_name)}")
end