multi_zip 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,142 @@
1
+ require 'multi_zip'
2
+
3
+ # can't use pry on old rubies or on rubinius
4
+ if RUBY_VERSION.to_f >= 2.0 && RUBY_ENGINE == 'ruby'
5
+ require 'pry'
6
+ require 'pry-byebug'
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.expect_with :rspec do |expectations|
11
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
12
+ end
13
+
14
+ config.mock_with :rspec do |mocks|
15
+ mocks.verify_partial_doubles = true
16
+ end
17
+
18
+ # This setting enables warnings. It's recommended, but in some cases may
19
+ # be too noisy due to issues in dependencies.
20
+ config.warnings = false
21
+
22
+ config.order = :random
23
+
24
+ # allow you to focus on just one test by adding 'focus: true' to the
25
+ # describe, context or it block.
26
+ config.filter_run :focus => true
27
+ config.run_all_when_everything_filtered = true
28
+
29
+ Kernel.srand config.seed
30
+ end
31
+
32
+ def invalid_archive_fixture_filename
33
+ 'spec/fixtures/invalid.zip'
34
+ end
35
+
36
+ def archive_fixture_filename
37
+ 'spec/fixtures/test.zip'
38
+ end
39
+
40
+ def archive_members
41
+ # assumed to reflect files in spec/fixtures/test/zip
42
+ {
43
+ 'file_1.txt' => 38, # member_name => size_in_bytes
44
+ 'file_2.txt' => 118,
45
+ 'dir_1/' => nil, # directory
46
+ 'dir_1/file_3.txt' => 229
47
+ }
48
+ end
49
+
50
+ def archive_member_size(member)
51
+ archive_members[member]
52
+ end
53
+
54
+ def archive_member_names
55
+ archive_members.keys.sort
56
+ end
57
+
58
+ def archive_member_files
59
+ Hash[archive_members.reject{|k,v| v.nil? }].keys.sort
60
+ end
61
+
62
+ def archive_member_directories
63
+ # assumed to reflect directories in spec/fixtures/test/zip
64
+ Hash[archive_members.select{|k,v| v.nil? }].keys.sort
65
+ end
66
+
67
+ def test_with_rubyzip?
68
+ # rubyzip requires ruby >= 1.9.2
69
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9.2")
70
+ gem 'rubyzip'
71
+ return true
72
+ end
73
+ false
74
+ rescue Gem::LoadError
75
+ false
76
+ end
77
+
78
+ def test_with_zipruby?
79
+ gem 'zipruby'
80
+ true
81
+ rescue Gem::LoadError
82
+ false
83
+ end
84
+
85
+ def backends_to_test
86
+ @backends_to_test ||= [
87
+ (test_with_zipruby? ? :zipruby : nil),
88
+ (test_with_rubyzip? ? :rubyzip : nil),
89
+ :archive_zip
90
+ ].compact
91
+ end
92
+
93
+ current_ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
94
+ warn "*** Backends to test under #{current_ruby_engine} #{RUBY_VERSION}: #{backends_to_test.map(&:to_s).join(', ')} ***"
95
+ excluded_backends = MultiZip::BACKENDS.keys - backends_to_test
96
+ if excluded_backends.length > 0
97
+ warn "*** Backends that will not be tested: #{excluded_backends.map(&:to_s).join(', ')} ***"
98
+ end
99
+
100
+ BACKEND_CONSTANTS = {}
101
+ BACKEND_CLASSES = {}
102
+
103
+ def set_backend_class(lib, klass)
104
+ BACKEND_CONSTANTS[lib.to_sym] = klass.constants
105
+ BACKEND_CLASSES[lib.to_sym] = klass
106
+ end
107
+
108
+ def backend_class(lib)
109
+ BACKEND_CLASSES[lib.to_sym]
110
+ end
111
+
112
+ def stash_constants(lib)
113
+ BACKEND_CONSTANTS[lib.to_sym].each do |cc|
114
+ Object.const_set("Stash#{lib}Zip#{cc}".to_sym, backend_class(lib).const_get(cc))
115
+ backend_class(lib).send(:remove_const, cc)
116
+ end
117
+ end
118
+
119
+ def apply_constants(lib)
120
+ BACKEND_CONSTANTS[lib.to_sym].each do |cc|
121
+ backend_class(lib).const_set(cc, Object.const_get("Stash#{lib}Zip#{cc}".to_sym))
122
+ Object.send(:remove_const, "Stash#{lib}Zip#{cc}".to_sym)
123
+ end
124
+ end
125
+
126
+ if test_with_rubyzip?
127
+ require 'zip'
128
+ set_backend_class(:rubyzip, Zip)
129
+ stash_constants(:rubyzip)
130
+ end
131
+
132
+ if test_with_zipruby?
133
+ require 'zipruby'
134
+ set_backend_class(:zipruby, Zip)
135
+ stash_constants(:zipruby)
136
+ end
137
+
138
+ require 'archive/zip'
139
+ # using `Archive` instead of `Archive::Zip`, because we need to stash the
140
+ # `::Zip` constant since we use that as the archive/zip fingerprint.
141
+ set_backend_class(:archive_zip, Archive)
142
+ stash_constants(:archive_zip)
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multi_zip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Nielsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ description: Abstracts zipping and unzipping using whatever gems are installed using
56
+ one consistent API. Provides swappable zipping/unzipping backends so you're not
57
+ tied to just one gem. Supports rubyzip, archive-zip, zipruby and others.
58
+ email:
59
+ - xunker@pyxidis.org
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - BACKEND_CONSTANTS.md
68
+ - Gemfile
69
+ - Guardfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - lib/multi_zip.rb
74
+ - lib/multi_zip/backend/archive_zip.rb
75
+ - lib/multi_zip/backend/rubyzip.rb
76
+ - lib/multi_zip/backend/zipruby.rb
77
+ - lib/multi_zip/errors.rb
78
+ - lib/multi_zip/version.rb
79
+ - multi_zip.gemspec
80
+ - spec/backend_shared_example.rb
81
+ - spec/fixtures/invalid.zip
82
+ - spec/fixtures/test.zip
83
+ - spec/lib/multi_zip/backend/archive_zip_spec.rb
84
+ - spec/lib/multi_zip/backend/rubyzip_spec.rb
85
+ - spec/lib/multi_zip/backend/zipruby_spec.rb
86
+ - spec/lib/multi_zip_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: https://github.com/xunker/multi_zip
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Abstracts zipping and unzipping using whatever gems are installed, automatically.
112
+ test_files:
113
+ - spec/backend_shared_example.rb
114
+ - spec/fixtures/invalid.zip
115
+ - spec/fixtures/test.zip
116
+ - spec/lib/multi_zip/backend/archive_zip_spec.rb
117
+ - spec/lib/multi_zip/backend/rubyzip_spec.rb
118
+ - spec/lib/multi_zip/backend/zipruby_spec.rb
119
+ - spec/lib/multi_zip_spec.rb
120
+ - spec/spec_helper.rb