Class: Crackup::SymlinkObject

Inherits:
Object
  • Object
show all
Includes:
FileSystemObject
Defined in:
lib/crackup/symlink_object.rb

Overview

Represents a symbolic link on the local filesystem.

Instance Attribute Summary collapse

Attributes included from FileSystemObject

#name, #name_hash

Instance Method Summary collapse

Methods included from FileSystemObject

from, #to_s

Constructor Details

#initialize(linkname) ⇒ SymlinkObject

– Public Instance Methods ++



16
17
18
19
20
21
22
23
24
# File 'lib/crackup/symlink_object.rb', line 16

def initialize(linkname)
  unless File.symlink?(linkname)
    raise ArgumentError, "#{linkname} is not a symbolic link"
  end
  
  super(linkname)
  
  @target = File.readlink(linkname)
end

Instance Attribute Details

#file_hashObject (readonly)

Returns the value of attribute file_hash.



10
11
12
# File 'lib/crackup/symlink_object.rb', line 10

def file_hash
  @file_hash
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/crackup/symlink_object.rb', line 10

def target
  @target
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/crackup/symlink_object.rb', line 10

def url
  @url
end

Instance Method Details

#==(symlink) ⇒ Object

Compares the specified Crackup::SymlinkObject to this one. Returns true if they’re the same, false if symlink is different.



28
29
30
# File 'lib/crackup/symlink_object.rb', line 28

def ==(symlink)
  return symlink.name == @name && symlink.target == @target
end

#removeObject

Removes this link from the remote location. This is actually a noop, since link data is just stored in the index.



34
35
36
# File 'lib/crackup/symlink_object.rb', line 34

def remove
  Crackup.debug "--> #{@name}"
end

#restore(path) ⇒ Object

Restores the remote copy of this link to the local path specified by path.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/crackup/symlink_object.rb', line 40

def restore(path)
  path     = path.chomp('/') + '/' + File.dirname(@name).delete(':')
  linkname = path + '/' + File.basename(@name)

  Crackup.debug "--> #{linkname}"
  
  # Create the path if it doesn't exist.

  unless File.directory?(path)
    begin
      FileUtils.mkdir_p(path)
    rescue => e
      raise Crackup::Error, "Unable to create local directory: #{path}"
    end
  end
  
  # Create the link.

  File.symlink(@target, linkname)
end

#updateObject

Uploads this link to the remote location. This is actually a noop, since link data is just stored in the index.



61
62
63
# File 'lib/crackup/symlink_object.rb', line 61

def update
  Crackup.debug "--> #{@name}"
end