zipline 0.0.13 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/lib/zipline/version.rb +1 -1
- data/lib/zipline/zip_generator.rb +29 -14
- data/lib/zipline.rb +1 -1
- data/spec/fakefile.txt +1 -0
- data/spec/lib/zipline/zip_generator_spec.rb +51 -10
- data/spec/spec_helper.rb +16 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37872610106cddacac2c39bb862c2dcc1527bd12
|
4
|
+
data.tar.gz: b17dacf33ec5aa463613ac8cb855582a2fb3b3df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8f4f222e763ee9429f693f861be3b18ba41040e43b0a89757538078f211ab9081a0573e4f5fc7ba90993750776e9135545ca6a45adad8cdfce7a744a5d7f18
|
7
|
+
data.tar.gz: 27fcb8575dd90c3c692fdab296a3a1e4824c8ccf1771f31456677a3644bc93e0f9f5e74661fa7cb48bd30357cdd2876798c0d7fa53656143b85ae7d4a854ac09
|
data/Gemfile
CHANGED
data/lib/zipline/version.rb
CHANGED
@@ -24,26 +24,41 @@ module Zipline
|
|
24
24
|
write_file(streamer, file, name)
|
25
25
|
end
|
26
26
|
|
27
|
+
# This extracts either a url or a local file from the provided file.
|
28
|
+
# Currently support carrierwave and paperclip local and remote storage.
|
29
|
+
# returns a hash of the form {url: aUrl} or {file: anIoObject}
|
27
30
|
def normalize(file)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
file
|
31
|
+
if defined?(CarrierWave::Uploader::Base) && file.is_a?(CarrierWave::Uploader::Base)
|
32
|
+
file = file.file
|
33
|
+
end
|
34
|
+
|
35
|
+
if defined?(Paperclip) && file.is_a?(Paperclip::Attachment)
|
36
|
+
if file.options[:storage] == :filesystem
|
37
|
+
{file: File.open(file.path)}
|
35
38
|
else
|
36
|
-
|
39
|
+
{url: file.expiring_url}
|
37
40
|
end
|
41
|
+
elsif defined?(CarrierWave::Storage::Fog::File) && file.is_a?(CarrierWave::Storage::Fog::File)
|
42
|
+
{url: file.url}
|
43
|
+
elsif defined?(CarrierWave::SanitizedFile) && file.is_a?(CarrierWave::SanitizedFile)
|
44
|
+
{file: File.open(file.path)}
|
45
|
+
elsif is_io?(file)
|
46
|
+
{file: file}
|
47
|
+
elsif file.respond_to? :url
|
48
|
+
{url: file.url}
|
49
|
+
elsif file.respond_to? :path
|
50
|
+
{file: File.open(file.path)}
|
51
|
+
elsif file.respond_to? :file
|
52
|
+
{file: File.open(file.file)}
|
53
|
+
else
|
54
|
+
raise(ArgumentError, 'Bad File/Stream')
|
38
55
|
end
|
39
|
-
file
|
40
56
|
end
|
41
57
|
|
42
58
|
def write_file(streamer, file, name)
|
43
59
|
streamer.write_deflated_file(name) do |writer_for_file|
|
44
|
-
if file
|
45
|
-
|
46
|
-
the_remote_url = file.respond_to?(:expiring_url) ? file.expiring_url : file.url
|
60
|
+
if file[:url]
|
61
|
+
the_remote_url = file[:url]
|
47
62
|
c = Curl::Easy.new(the_remote_url) do |curl|
|
48
63
|
curl.on_body do |data|
|
49
64
|
writer_for_file << data
|
@@ -51,8 +66,8 @@ module Zipline
|
|
51
66
|
end
|
52
67
|
end
|
53
68
|
c.perform
|
54
|
-
elsif
|
55
|
-
IO.copy_stream(file, writer_for_file)
|
69
|
+
elsif file[:file]
|
70
|
+
IO.copy_stream(file[:file], writer_for_file)
|
56
71
|
else
|
57
72
|
raise(ArgumentError, 'Bad File/Stream')
|
58
73
|
end
|
data/lib/zipline.rb
CHANGED
@@ -19,6 +19,6 @@ module Zipline
|
|
19
19
|
response.sending_file = true
|
20
20
|
response.cache_control[:public] ||= false
|
21
21
|
self.response_body = zip_generator
|
22
|
-
self.response.headers['Last-Modified'] = Time.now.
|
22
|
+
self.response.headers['Last-Modified'] = Time.now.httpdate
|
23
23
|
end
|
24
24
|
end
|
data/spec/fakefile.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hello world
|
@@ -26,35 +26,76 @@ describe Zipline::ZipGenerator do
|
|
26
26
|
context "CarrierWave" do
|
27
27
|
context "Remote" do
|
28
28
|
let(:file){ CarrierWave::Storage::Fog::File.new(nil,nil,nil) }
|
29
|
-
it "
|
29
|
+
it "extracts the url" do
|
30
|
+
allow(file).to receive(:url).and_return('fakeurl')
|
30
31
|
expect(File).not_to receive(:open)
|
31
|
-
expect(generator.normalize(file)).to
|
32
|
+
expect(generator.normalize(file)).to eq({url: 'fakeurl'})
|
32
33
|
end
|
33
34
|
end
|
34
35
|
context "Local" do
|
35
36
|
let(:file){ CarrierWave::SanitizedFile.new(Tempfile.new('t')) }
|
36
37
|
it "creates a File" do
|
37
|
-
|
38
|
+
allow(file).to receive(:path).and_return('spec/fakefile.txt')
|
39
|
+
normalized = generator.normalize(file)
|
40
|
+
expect(normalized.keys).to include(:file)
|
41
|
+
expect(normalized[:file]).to be_a File
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context "CarrierWave::Uploader::Base" do
|
45
|
+
let(:uploader) { Class.new(CarrierWave::Uploader::Base).new }
|
46
|
+
|
47
|
+
context "Remote" do
|
48
|
+
let(:file){ CarrierWave::Storage::Fog::File.new(nil,nil,nil) }
|
49
|
+
it "extracts the url" do
|
50
|
+
allow(uploader).to receive(:file).and_return(file)
|
51
|
+
allow(file).to receive(:url).and_return('fakeurl')
|
52
|
+
expect(File).not_to receive(:open)
|
53
|
+
expect(generator.normalize(uploader)).to eq({url: 'fakeurl'})
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "Local" do
|
58
|
+
let(:file){ CarrierWave::SanitizedFile.new(Tempfile.new('t')) }
|
59
|
+
it "creates a File" do
|
60
|
+
allow(uploader).to receive(:file).and_return(file)
|
61
|
+
allow(file).to receive(:path).and_return('spec/fakefile.txt')
|
62
|
+
normalized = generator.normalize(uploader)
|
63
|
+
expect(normalized.keys).to include(:file)
|
64
|
+
expect(normalized[:file]).to be_a File
|
65
|
+
end
|
38
66
|
end
|
39
67
|
end
|
40
68
|
end
|
41
69
|
context "Paperclip" do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
70
|
+
context "Local" do
|
71
|
+
let(:file){ Paperclip::Attachment.new(:name, :instance) }
|
72
|
+
it "creates a File" do
|
73
|
+
allow(file).to receive(:path).and_return('spec/fakefile.txt')
|
74
|
+
normalized = generator.normalize(file)
|
75
|
+
expect(normalized.keys).to include(:file)
|
76
|
+
expect(normalized[:file]).to be_a File
|
77
|
+
end
|
78
|
+
end
|
79
|
+
context "Remote" do
|
80
|
+
let(:file){ Paperclip::Attachment.new(:name, :instance, storage: :s3) }
|
81
|
+
it "creates a URL" do
|
82
|
+
allow(file).to receive(:expiring_url).and_return('fakeurl')
|
83
|
+
expect(File).to_not receive(:open)
|
84
|
+
expect(generator.normalize(file)).to include(url: 'fakeurl')
|
85
|
+
end
|
46
86
|
end
|
47
87
|
end
|
48
88
|
context "Fog" do
|
49
|
-
it "
|
89
|
+
it "extracts url" do
|
90
|
+
allow(file).to receive(:url).and_return('fakeurl')
|
50
91
|
expect(File).not_to receive(:open)
|
51
|
-
expect(generator.normalize(file)).to
|
92
|
+
expect(generator.normalize(file)).to eq(url: 'fakeurl')
|
52
93
|
end
|
53
94
|
end
|
54
95
|
context "IOStream" do
|
55
96
|
let(:file){ StringIO.new('passthrough')}
|
56
97
|
it "passes through" do
|
57
|
-
expect(generator.normalize(file)).to
|
98
|
+
expect(generator.normalize(file)).to eq(file: file)
|
58
99
|
end
|
59
100
|
end
|
60
101
|
context "invalid" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,27 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext'
|
2
4
|
require 'zipline'
|
5
|
+
require 'aws-sdk'
|
3
6
|
require 'paperclip'
|
4
7
|
require 'fog'
|
8
|
+
require 'fog-aws'
|
5
9
|
require 'carrierwave'
|
6
10
|
|
7
11
|
Dir["#{File.expand_path('..', __FILE__)}/support/**/*.rb"].each { |f| require f }
|
8
12
|
|
13
|
+
CarrierWave.configure do |config|
|
14
|
+
config.fog_provider = 'fog/aws'
|
15
|
+
config.fog_credentials = {
|
16
|
+
provider: 'AWS',
|
17
|
+
aws_access_key_id: 'dummy',
|
18
|
+
aws_secret_access_key: 'data',
|
19
|
+
region: 'us-west-2',
|
20
|
+
}
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
9
25
|
|
10
26
|
RSpec.configure do |config|
|
11
27
|
config.color = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zipline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ram Dobson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip_tricks
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/zipline.rb
|
85
85
|
- lib/zipline/version.rb
|
86
86
|
- lib/zipline/zip_generator.rb
|
87
|
+
- spec/fakefile.txt
|
87
88
|
- spec/lib/zipline/zip_generator_spec.rb
|
88
89
|
- spec/spec_helper.rb
|
89
90
|
- zipline.gemspec
|
@@ -106,10 +107,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.6.
|
110
|
+
rubygems_version: 2.6.14
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: stream zip files from rails
|
113
114
|
test_files:
|
115
|
+
- spec/fakefile.txt
|
114
116
|
- spec/lib/zipline/zip_generator_spec.rb
|
115
117
|
- spec/spec_helper.rb
|