Class: Omnizip::LinkHandler::HardLink
- Inherits:
-
Object
- Object
- Omnizip::LinkHandler::HardLink
- Defined in:
- lib/omnizip/link_handler/hard_link.rb
Overview
Model for hard links
Instance Attribute Summary collapse
-
#inode ⇒ Object
readonly
Returns the value of attribute inode.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
-
.deserialize(data, path: nil) ⇒ Object
Deserialize from archive storage.
Instance Method Summary collapse
-
#create(link_path) ⇒ Object
Create the hard link on the filesystem.
-
#hardlink? ⇒ Boolean
Check if this is a hard link.
-
#initialize(target:, path: nil, inode: nil) ⇒ HardLink
constructor
A new instance of HardLink.
-
#inspect ⇒ Object
Inspect representation.
-
#link_type ⇒ Object
Get the link type as string.
-
#serialize ⇒ Object
Serialize for archive storage.
-
#symlink? ⇒ Boolean
Check if this is a symbolic link.
-
#to_h ⇒ Object
Convert to hash representation.
-
#to_s ⇒ Object
String representation.
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
#inode ⇒ Object (readonly)
Returns the value of attribute inode.
7 8 9 |
# File 'lib/omnizip/link_handler/hard_link.rb', line 7 def inode @inode end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/omnizip/link_handler/hard_link.rb', line 7 def path @path end |
#target ⇒ Object (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
48 49 50 |
# File 'lib/omnizip/link_handler/hard_link.rb', line 48 def hardlink? true end |
#inspect ⇒ Object
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 |
#link_type ⇒ Object
Get the link type as string
53 54 55 |
# File 'lib/omnizip/link_handler/hard_link.rb', line 53 def link_type "hardlink" end |
#serialize ⇒ Object
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
43 44 45 |
# File 'lib/omnizip/link_handler/hard_link.rb', line 43 def symlink? false end |
#to_h ⇒ Object
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_s ⇒ Object
String representation
68 69 70 |
# File 'lib/omnizip/link_handler/hard_link.rb', line 68 def to_s "#{@path} -> #{@target} (hard link)" end |