Class: ZipDir::Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/zip_dir/dir.rb

Direct Known Subclasses

Zipper

Defined Under Namespace

Classes: Proxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#copy_pathObject (readonly)

Returns the value of attribute copy_path.


3
4
5
# File 'lib/zip_dir/dir.rb', line 3

def copy_path
  @copy_path
end

Instance Method Details

#cleanupObject


26
27
28
29
30
# File 'lib/zip_dir/dir.rb', line 26

def cleanup
  FileUtils.remove_entry_secure copy_path if copy_path
  @copy_path = nil
  @generated = false
end

#generate(source_path = nil, options = {}) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zip_dir/dir.rb', line 9

def generate(source_path=nil, options={})
  cleanup if generated?

  @copy_path = ::Dir.mktmpdir
  proxy = Proxy.new(copy_path)
  if source_path
    raise "Should not give block and source_path: #{source_path}" if block_given?
    proxy.add_path source_path, options
  else
    yield proxy
  end

  ::Dir.new(copy_path)
ensure
  @generated = true
end

#generated?Boolean

Returns:

  • (Boolean)

5
6
7
# File 'lib/zip_dir/dir.rb', line 5

def generated?
  !!@generated
end