Class: Omnizip::LinkHandler::SymbolicLink

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/link_handler/symbolic_link.rb

Overview

Model for symbolic links

Constant Summary collapse

0o120777

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target:, path: nil) ⇒ SymbolicLink

Returns a new instance of SymbolicLink.



12
13
14
15
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 12

def initialize(target:, path: nil)
  @target = target
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 7

def path
  @path
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 7

def target
  @target
end

Class Method Details

.deserialize(target_data, path: nil) ⇒ Object

Deserialize from archive storage



33
34
35
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 33

def self.deserialize(target_data, path: nil)
  new(target: target_data, path: path)
end

Instance Method Details

#create(link_path) ⇒ Object

Create the symbolic link on the filesystem



18
19
20
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 18

def create(link_path)
  LinkHandler.create_symlink(@target, link_path)
end

#hardlink?Boolean

Check if this is a hard link

Returns:

  • (Boolean)


43
44
45
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 43

def hardlink?
  false
end

#inspectObject

Inspect representation



68
69
70
71
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 68

def inspect
  "#<Omnizip::LinkHandler::SymbolicLink target=#{@target.inspect} " \
    "path=#{@path.inspect}>"
end

Get the link type as string



48
49
50
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 48

def link_type
  "symlink"
end

#permissionsObject

Get Unix permissions for symbolic links



23
24
25
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 23

def permissions
  SYMLINK_PERMISSIONS
end

#serializeObject

Serialize for archive storage (returns the target path)



28
29
30
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 28

def serialize
  @target
end

#symlink?Boolean

Check if this is a symbolic link

Returns:

  • (Boolean)


38
39
40
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 38

def symlink?
  true
end

#to_hObject

Convert to hash representation



53
54
55
56
57
58
59
60
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 53

def to_h
  {
    type: :symlink,
    target: @target,
    path: @path,
    permissions: permissions,
  }
end

#to_sObject

String representation



63
64
65
# File 'lib/omnizip/link_handler/symbolic_link.rb', line 63

def to_s
  "#{@path} -> #{@target} (symlink)"
end