zip_dir 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0fe1cd41c0b83dd595962ce0b0242b5aff1a4f4a
4
+ data.tar.gz: 22106c6db7edcdd3af3172cba7f72a7bb2946bb0
5
+ SHA512:
6
+ metadata.gz: 10207faa6757782af155611013bc82d18137d8d9b4d6e434d755e363a6a34da6a67a7d9cae0a85daf3eed48426403c847c0602ec5c59b3678f6fa62811b68866
7
+ data.tar.gz: 32444d4ebd2e080675a721ee5022215777e9d04071d38274f834fd0dec10eb261aee573546346633c77935e303475785c914a1dbe8fcaa8a49f6dfb28bb34fe1
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .idea/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zip_dir.gemspec
4
+ gemspec
5
+
6
+ gem "bundler", "> 1.3"
7
+ gem "rake", "~> 10.0"
8
+
9
+ group :test do
10
+ gem "rspec"
11
+ gem "codeclimate-test-reporter"
12
+ gem 'pry-byebug'
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Steve Chung
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # ZipDir
2
+
3
+ Zip and unzip directories.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'zip_dir'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install zip_dir
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # Zip
25
+ zipper = ZipDir::Zipper.new
26
+ zip_file = zipper.generate do |z|
27
+ z.add_path __some_path_to_directory__
28
+ z.add_path __another_path_to_directory__ # does a shell "cp -r" operation
29
+ end
30
+ zip_file == zipper.file # => true
31
+
32
+
33
+ # Unzip
34
+ unzip_path = ZipDir::Unzipper.new(zip_file.path).unzip_path
35
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "zip_dir"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ class Dir
2
+ class << self
3
+ def clean_entries(dir)
4
+ entries = entries(dir)
5
+ entries.delete "."
6
+ entries.delete ".."
7
+ entries
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ module ZipDir
2
+ class Unzipper
3
+ attr_reader :zip_path
4
+ def initialize(zip_path)
5
+ @zip_path, @unzip_path = zip_path, Dir.mktmpdir
6
+ end
7
+
8
+ def cleanup
9
+ @unzipped = false
10
+ FileUtils.remove_entry_secure @unzip_path
11
+ end
12
+
13
+ def unzip_path
14
+ unzip unless unzipped?
15
+ @unzip_path
16
+ end
17
+
18
+ def unzipped?
19
+ !!@unzipped
20
+ end
21
+
22
+ def unzip
23
+ Zip::File.open(zip_path) do |zip_file|
24
+ zip_file.each do |entry|
25
+ file_path = "#{@unzip_path}/#{entry.name}"
26
+ entry.extract(file_path) unless File.exists?(file_path)
27
+ end
28
+ end
29
+ @unzipped = true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module ZipDir
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,65 @@
1
+ module ZipDir
2
+ class Zipper
3
+ attr_reader :copy_path, :file
4
+
5
+ def initialize
6
+ @copy_path = Dir.mktmpdir
7
+ end
8
+
9
+ def add_path(source_path)
10
+ FileUtils.cp_r source_path, copy_path
11
+ end
12
+ alias_method :<<, :add_path
13
+
14
+ def generated?
15
+ !!file
16
+ end
17
+
18
+ def generate(filename="zipper")
19
+ yield self
20
+ @file = Zip.new(copy_path, filename).file
21
+ end
22
+
23
+ def cleanup
24
+ FileUtils.remove_entry_secure copy_path
25
+ end
26
+
27
+ class Zip
28
+ attr_reader :source_path
29
+ def initialize(source_path, filename)
30
+ @source_path, @file = source_path, Tempfile.new([filename, ".zip"])
31
+ end
32
+
33
+ def file
34
+ generate unless generated?
35
+ @file
36
+ end
37
+
38
+ def generate
39
+ ::Zip::File.open(@file.path, ::Zip::File::CREATE) do |zip_io|
40
+ zip_path(zip_io)
41
+ end
42
+ @generated = true
43
+ end
44
+
45
+ def generated?
46
+ !!@generated
47
+ end
48
+
49
+ def zip_path(zip_io, relative_path="")
50
+ entries = Dir.clean_entries(relative_path.empty? ? source_path : File.join(source_path, relative_path))
51
+ entries.each do |entry|
52
+ relative_entry_path = relative_path.empty? ? entry : File.join(relative_path, entry)
53
+ source_entry_path = File.join(source_path, relative_entry_path)
54
+
55
+ if File.directory?(source_entry_path)
56
+ zip_io.mkdir relative_entry_path
57
+ zip_path zip_io, relative_entry_path
58
+ else
59
+ zip_io.add relative_entry_path, source_entry_path
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
data/lib/zip_dir.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "zip_dir/version"
2
+
3
+ require 'zip'
4
+
5
+ require 'zip_dir/core_ext/dir'
6
+
7
+ require 'zip_dir/zipper'
8
+ require 'zip_dir/unzipper'
9
+
10
+ module ZipDir
11
+ # Your code goes here...
12
+ end
data/zip_dir.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zip_dir/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zip_dir"
8
+ spec.version = ZipDir::VERSION
9
+ spec.authors = ["Steve Chung"]
10
+ spec.email = ["hello@stevenchung.ca"]
11
+
12
+ spec.summary = "Zip and unzip directories."
13
+ spec.homepage = "https://github.com/FinalCAD/zip_dir"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rubyzip", '>= 1.0.0'
22
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zip_dir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Chung
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ description:
28
+ email:
29
+ - hello@stevenchung.ca
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - lib/zip_dir.rb
44
+ - lib/zip_dir/core_ext/dir.rb
45
+ - lib/zip_dir/unzipper.rb
46
+ - lib/zip_dir/version.rb
47
+ - lib/zip_dir/zipper.rb
48
+ - zip_dir.gemspec
49
+ homepage: https://github.com/FinalCAD/zip_dir
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.5.1
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Zip and unzip directories.
73
+ test_files: []