Class: Omnizip::Temp::ArchiveHelper

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

Overview

Helper class for temp archive operations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, format) ⇒ ArchiveHelper

Returns a new instance of ArchiveHelper.



119
120
121
122
# File 'lib/omnizip/temp.rb', line 119

def initialize(path, format)
  @path = path
  @format = format
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



117
118
119
# File 'lib/omnizip/temp.rb', line 117

def format
  @format
end

#pathObject (readonly)

Returns the value of attribute path.



117
118
119
# File 'lib/omnizip/temp.rb', line 117

def path
  @path
end

Instance Method Details

#add_file(name, data = nil, &block) ⇒ Object

Add file to archive

Parameters:

  • name (String)

    Entry name

  • data (String) (defaults to: nil)

    Entry data



127
128
129
130
131
132
133
134
135
136
# File 'lib/omnizip/temp.rb', line 127

def add_file(name, data = nil, &block)
  data = yield if block

  case format
  when :zip
    Omnizip::Zip::File.create(path) do |zip|
      zip.add(name) { data }
    end
  end
end