Class: Omnizip::LinkHandler::HardLink

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

Overview

Model for hard links

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target:, path: nil, inode: nil) ⇒ HardLink

Returns a new instance of HardLink.



9
10
11
12
13
# File 'lib/omnizip/link_handler/hard_link.rb', line 9

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

Instance Attribute Details

#inodeObject (readonly)

Returns the value of attribute inode.



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

def inode
  @inode
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

Class Method Details

.deserialize(data, path: nil) ⇒ Object

Deserialize from archive storage



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/omnizip/link_handler/hard_link.rb', line 29

def self.deserialize(data, path: nil)
  if data.is_a?(Hash)
    new(
      target: data[:target] || data["target"],
      path: path,
      inode: data[:inode] || data["inode"],
    )
  else
    # Legacy format: just the target path
    new(target: data, path: path)
  end
end

Instance Method Details

#create(link_path) ⇒ Object

Create the hard link on the filesystem



16
17
18
# File 'lib/omnizip/link_handler/hard_link.rb', line 16

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

#hardlink?Boolean

Check if this is a hard link

Returns:

  • (Boolean)


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

def hardlink?
  true
end

#inspectObject

Inspect representation



73
74
75
76
# File 'lib/omnizip/link_handler/hard_link.rb', line 73

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

Get the link type as string



53
54
55
# File 'lib/omnizip/link_handler/hard_link.rb', line 53

def link_type
  "hardlink"
end

#serializeObject

Serialize for archive storage



21
22
23
24
25
26
# File 'lib/omnizip/link_handler/hard_link.rb', line 21

def serialize
  {
    target: @target,
    inode: @inode,
  }
end

#symlink?Boolean

Check if this is a symbolic link

Returns:

  • (Boolean)


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

def symlink?
  false
end

#to_hObject

Convert to hash representation



58
59
60
61
62
63
64
65
# File 'lib/omnizip/link_handler/hard_link.rb', line 58

def to_h
  {
    type: :hardlink,
    target: @target,
    path: @path,
    inode: @inode,
  }
end

#to_sObject

String representation



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

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