Class: Distillery::ROM::Path::Archive

Inherits:
Distillery::ROM::Path show all
Defined in:
lib/distillery/rom/path/archive.rb

Overview

Path from archive, binding archive and entry together.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive, entry) ⇒ Archive

Create a an Archive Path instance

Parameters:

  • archive (ROMArchive)

    archive instance

  • entry (String)

    archive entry



37
38
39
40
# File 'lib/distillery/rom/path/archive.rb', line 37

def initialize(archive, entry)
    @archive = archive
    @entry   = entry
end

Instance Attribute Details

#archiveROMArchive (readonly)

Returns the value of attribute archive

Returns:



97
98
99
# File 'lib/distillery/rom/path/archive.rb', line 97

def archive
  @archive
end

Class Method Details

.separatorString, Array

Get the separator used to distinguish archive file from entry

Returns:

  • (String, Array)


27
28
29
# File 'lib/distillery/rom/path/archive.rb', line 27

def self.separator
    @@separator
end

.separator=(sep) ⇒ Object

Set the separator used to distinguish archive file from entry

Parameters:

  • sep (String)

    separator



18
19
20
# File 'lib/distillery/rom/path/archive.rb', line 18

def self.separator=(sep)
    @@separator = sep.dup.freeze
end

Instance Method Details

#basenameString

Get path basename

Returns:

  • (String)


64
65
66
# File 'lib/distillery/rom/path/archive.rb', line 64

def basename
    ::File.basename(self.entry)
end

#copy(to, length = nil, offset = 0, force: false, link: :hard) ⇒ Boolean

Copy ROM content to the filesystem, possibly using link if requested.

Parameters:

  • to (String)

    file destination

  • length (Integer, nil) (defaults to: nil)

    data length to be copied

  • offset (Integer) (defaults to: 0)

    data offset

  • force (Boolean) (defaults to: false)

    remove previous file if necessary

  • link (:hard, :sym, nil) (defaults to: :hard)

    use link instead of copy if possible

Returns:

  • (Boolean)

    status of the operation



79
80
81
82
# File 'lib/distillery/rom/path/archive.rb', line 79

def copy(to, length = nil, offset = 0, force: false, link: :hard)
    # XXX: improve like String
    @archive.extract(@entry, to, length, offset, force: force)
end

#delete!Boolean

Delete physical content.

Returns:

  • (Boolean)


91
92
93
# File 'lib/distillery/rom/path/archive.rb', line 91

def delete!
    @archive.delete!(@entry)
end

#entryString

Entry

Returns:

  • (String)


59
60
61
# File 'lib/distillery/rom/path/archive.rb', line 59

def entry
    @entry
end

#fileString

File directly accessible on the file system

Returns:

  • (String)


49
50
51
# File 'lib/distillery/rom/path/archive.rb', line 49

def file
    @archive.file
end

#groupingObject



69
70
71
# File 'lib/distillery/rom/path/archive.rb', line 69

def grouping
    [ self.storage, self.entry, @archive.size ]
end

#reader {|io| ... } ⇒ Object

Note:

Can be costly, prefer existing #copy if possible

ROM reader

Yield Parameters:

  • io (#read)

    stream for reading

Returns:

  • block value



74
75
76
# File 'lib/distillery/rom/path/archive.rb', line 74

def reader(&block)
    @archive.reader(@entry, &block)
end

#rename(path, force: false) ⇒ Boolean

Note:

Renaming could lead to silent removing if same ROM is on its way

Rename ROM and physical content.

Parameters:

  • path (String)

    new ROM path

  • force (Boolean) (defaults to: false)

    remove previous file if necessary

Returns:

  • (Boolean)

    status of the operation



85
86
87
88
# File 'lib/distillery/rom/path/archive.rb', line 85

def rename(path, force: false)
    # XXX: improve like String
    @archive.rename(@entry, path, force: force)
end

#storageString

File or directory that is considered the storage space for entries

Returns:

  • (String)


54
55
56
# File 'lib/distillery/rom/path/archive.rb', line 54

def storage
    self.file
end

#to_s(separator = nil) ⇒ String

Path value as string.

Returns:

  • (String)


43
44
45
46
# File 'lib/distillery/rom/path/archive.rb', line 43

def to_s(separator = nil)
    separator ||= @@separator
    "#{self.file}#{separator[0]}#{self.entry}#{separator[1]}"
end