Class: Qrpm::FileNode
- Inherits:
-
HashNode
- Object
- Node
- ContainerNode
- HashNode
- Qrpm::FileNode
- Defined in:
- lib/qrpm/node.rb
Overview
A file. Always an element of a DirectoryNode object
A file is a hash with an integer key and with the following expressions as members:
file Source file. The source file path is prefixed with $srcdir if
defined. May be nil
name Basename of the destination file. This defaults to the
basename of the source file/symlink/reflink. The full path of
the destination file is computed by prefixing the path of the
parent directory
reflink Path on the target filesystem to the source of the reflink
(hard-link). May be nil
symlink Path on the target filesystem to the source of the symlink.
May be nil
perm Permissions of the target file in chmod(1) octal or rwx
notation. May be nil
Exactly one of ‘file’, ‘symlink’, and ‘reflink’ must be defined. ‘perm’ can’t be used together with ‘symlink’ or ‘reflink’
When interpolated the following methods are defined on a FileNode:
srcpath Path to source file
dstpath Path to destination file
dstname Basename of destination file
reflink Path to source link
symlink Path to source link
perm Permissions
Instance Attribute Summary collapse
-
#dstname ⇒ Object
readonly
Destination file name.
-
#dstpath ⇒ Object
readonly
Destination file path.
-
#perm ⇒ Object
readonly
Permissions of destination file.
-
#reflink ⇒ Object
readonly
Hard-link file.
-
#srcpath ⇒ Object
readonly
Source file.
-
#symlink ⇒ Object
readonly
Symbolic link file.
Attributes inherited from Node
Class Method Summary collapse
-
.make(parent, arg) ⇒ Object
:call-seq: FileNode.make(directory_node, filename) FileNode.make(directory_node, hash).
Instance Method Summary collapse
-
#directory ⇒ Object
Directory.
-
#dst ⇒ Object
Name of destination.
-
#file? ⇒ Boolean
Query methods.
-
#initialize(parent, name) ⇒ FileNode
constructor
A new instance of FileNode.
- #interpolate(dict) ⇒ Object
- #link? ⇒ Boolean
- #reflink? ⇒ Boolean
-
#signature ⇒ Object
Signature.
-
#src ⇒ Object
Path to source file.
- #symlink? ⇒ Boolean
Methods inherited from HashNode
Methods inherited from ContainerNode
Methods inherited from Node
#class_name, #dot, #dump, #inspect, #interpolated?, #traverse, #variables
Constructor Details
#initialize(parent, name) ⇒ FileNode
Returns a new instance of FileNode.
283 284 285 286 287 |
# File 'lib/qrpm/node.rb', line 283 def initialize(parent, name) constrain parent, DirectoryNode constrain name, Integer super end |
Instance Attribute Details
#dstname ⇒ Object (readonly)
Destination file name
263 264 265 |
# File 'lib/qrpm/node.rb', line 263 def dstname @dstname end |
#dstpath ⇒ Object (readonly)
Destination file path
260 261 262 |
# File 'lib/qrpm/node.rb', line 260 def dstpath @dstpath end |
#perm ⇒ Object (readonly)
Permissions of destination file. Perm is always a string
272 273 274 |
# File 'lib/qrpm/node.rb', line 272 def perm @perm end |
#reflink ⇒ Object (readonly)
Hard-link file
266 267 268 |
# File 'lib/qrpm/node.rb', line 266 def reflink @reflink end |
#srcpath ⇒ Object (readonly)
Source file. This is the relative path to the file in the build directory except for link files. Link files have a path on the target filesystem as path. It is the interpolated value of #expr
257 258 259 |
# File 'lib/qrpm/node.rb', line 257 def srcpath @srcpath end |
#symlink ⇒ Object (readonly)
Symbolic link file
269 270 271 |
# File 'lib/qrpm/node.rb', line 269 def symlink @symlink end |
Class Method Details
Instance Method Details
#directory ⇒ Object
Directory
275 |
# File 'lib/qrpm/node.rb', line 275 def directory = parent.directory |
#dst ⇒ Object
Name of destination. Returns the QRPM source expression or the interpolated result if the FileNode object has been interpolated. Used by Qrpm#dump
327 328 329 330 331 332 333 |
# File 'lib/qrpm/node.rb', line 327 def dst if expr["name"] interpolated? ? expr["name"].value : expr["name"].expr.source else File.basename(src) end end |
#file? ⇒ Boolean
Query methods
278 |
# File 'lib/qrpm/node.rb', line 278 def file? = !link? |
#interpolate(dict) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/qrpm/node.rb', line 289 def interpolate(dict) super exprs.each { |e| e.interpolate(dict) } @srcpath = value[%w(file symlink reflink).find { |k| expr.key?(k) }].value @dstname = value["name"]&.value || File.basename(srcpath) @dstpath = "#{parent.directory}/#{@dstname}" @reflink = value["reflink"]&.value @symlink = value["symlink"]&.value @perm = value["perm"]&.value self end |
#link? ⇒ Boolean
279 |
# File 'lib/qrpm/node.rb', line 279 def link? = symlink? || reflink? |
#reflink? ⇒ Boolean
280 |
# File 'lib/qrpm/node.rb', line 280 def reflink? = @expr.key?("reflink") |
#signature ⇒ Object
Signature. Used in tests
314 |
# File 'lib/qrpm/node.rb', line 314 def signature = "FileNode(#{name},#{expr["file"].source})" |
#src ⇒ Object
Path to source file. Returns the QRPM source expression or the interpolated result if the FileNode object has been interpolated. Used by Qrpm#dump
319 320 321 322 |
# File 'lib/qrpm/node.rb', line 319 def src e = expr["file"] || expr["reflink"] || expr["symlink"] interpolated? ? e.value : e.source end |
#symlink? ⇒ Boolean
281 |
# File 'lib/qrpm/node.rb', line 281 def symlink? = @expr.key?("symlink") |