Class: Kiip::Entry

Inherits:
Hashie::Dash
  • Object
show all
Defined in:
lib/kiip/entry.rb

Instance Method Summary collapse

Instance Method Details

#restoreObject

restores the entry to it’s original place



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kiip/entry.rb', line 8

def restore
  remove_source if correct_link?

  # if file exists, remove or return
  if File.exist?(expanded_source)
    cli.agree("#{source} exists. Remove it?") ? remove_source : return
  end

  puts "copy #{target} to #{source}" if verbose?
  FileUtils.copy_entry(target, expanded_source) unless dry?
end

#statusObject



33
34
35
36
37
38
39
40
41
# File 'lib/kiip/entry.rb', line 33

def status
  return :linked if correct_link?
  return :symlink if File.symlink?(expanded_source)
  return :directory if File.directory?(expanded_source)
  return :file if File.file?(expanded_source)
  return :not_existent unless File.exist?(expanded_source)

  raise 'unknown status'
end

removes the source. If source is not a link to target, it asks the users.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kiip/entry.rb', line 21

def unlink
  if not File.exist?(expanded_source)
    cli.say "#{source} does not exist." if file_options[:verbose]
    return
  end

  if correct_link? or cli.agree("#{source} is not a symlink to #{target}. Still remove it?")
    puts "removing #{source}" if file_options[:verbose]
    FileUtils.remove_entry(expanded_source, **file_options) unless file_options[:noop]
  end
end