Sha256: 78abfd8e6863114a64917f951b2af4ae6e61344ed619fb57592a53ad5596bf97

Contents?: true

Size: 1.11 KB

Versions: 17

Compression:

Stored size: 1.11 KB

Contents

module Workspace
  class WorkspaceFile
    module Archive
      extend ActiveSupport::Concern

      def extract(target_dir)
        target_dir.create
        if extension == "zip"
          extract_zip(target_dir)
        elsif extension == "gz"
          extract_gz(target_dir)
        end
        self
      end

      private

      def extract_zip(target_dir)
        require "zip"
        Zip::File.open(to_s) do |archive|
          archive.each do |entry|
            entry.extract(File.join(target_dir.to_s, entry.name))
          end
        end
      end

      def extract_gz(target_dir)
        require 'rubygems/package'
        workspace_dir = target_dir.root_dir
        archive = Gem::Package::TarReader.new(Zlib::GzipReader.open(to_s))
        archive.rewind
        archive.each do |entry|
          if entry.directory?
            archive_dir = workspace_dir.dir(entry.full_name)
            archive_dir.create
          elsif entry.file?
            archive_file = workspace_dir.file(entry.full_name)
            archive_file.write(entry.read)
          end
        end
        archive.close
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
maglove-1.1.5 lib/workspace/workspace_file/archive.rb
maglove-1.1.4 lib/workspace/workspace_file/archive.rb
maglove-1.1.3 lib/workspace/workspace_file/archive.rb
maglove-2.0.4 lib/workspace/workspace_file/archive.rb
maglove-2.0.2 lib/workspace/workspace_file/archive.rb
maglove-2.0.1 lib/workspace/workspace_file/archive.rb
maglove-1.1.2 lib/workspace/workspace_file/archive.rb
maglove-2.0.0 lib/workspace/workspace_file/archive.rb
maglove-1.1.1 lib/workspace/workspace_file/archive.rb
maglove-1.1.0 lib/workspace/workspace_file/archive.rb
maglove-1.0.9 lib/workspace/workspace_file/archive.rb
maglove-1.0.8 lib/workspace/workspace_file/archive.rb
maglove-1.0.7 lib/workspace/workspace_file/archive.rb
maglove-1.0.5 lib/workspace/workspace_file/archive.rb
maglove-1.0.4 lib/workspace/workspace_file/archive.rb
maglove-1.0.3 lib/workspace/workspace_file/archive.rb
maglove-1.0.2 lib/workspace/workspace_file/archive.rb