zipline 0.0.13 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4432974ae414c5818803a87592a48724c6529cf4
4
- data.tar.gz: 49d506143661ddcee1d31bd0bcf01552cf69f330
3
+ metadata.gz: 37872610106cddacac2c39bb862c2dcc1527bd12
4
+ data.tar.gz: b17dacf33ec5aa463613ac8cb855582a2fb3b3df
5
5
  SHA512:
6
- metadata.gz: 6542c37c2b31036c03a7df68cd986dc68a62a823fcbe92ff08892c2f68b31aae8f405445d05f3ce4ac36605fd4ab3d535fdce38538e4c1e14e746f3ec9d28398
7
- data.tar.gz: 1897313e5748f76d89fbffd238327cbf8058b615f97f0af24f7379476b8e1740958cdaf4ffdd53683f05f3d1e2f1cdd1c16d820473cc2fba8f4c1c5155090296
6
+ metadata.gz: bd8f4f222e763ee9429f693f861be3b18ba41040e43b0a89757538078f211ab9081a0573e4f5fc7ba90993750776e9135545ca6a45adad8cdfce7a744a5d7f18
7
+ data.tar.gz: 27fcb8575dd90c3c692fdab296a3a1e4824c8ccf1771f31456677a3644bc93e0f9f5e74661fa7cb48bd30357cdd2876798c0d7fa53656143b85ae7d4a854ac09
data/Gemfile CHANGED
@@ -7,6 +7,9 @@ group :development, :test do
7
7
  gem 'rubyzip', '~> 1.2'
8
8
  gem 'rspec', '~> 3'
9
9
  gem 'fog'
10
+ gem 'fog-aws'
11
+ gem 'activesupport'
12
+ gem 'aws-sdk'
10
13
  gem 'carrierwave'
11
14
  gem 'paperclip'
12
15
  end
@@ -1,3 +1,3 @@
1
1
  module Zipline
2
- VERSION = "0.0.13"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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
- unless is_io?(file)
29
- if file.respond_to?(:url) || file.respond_to?(:expiring_url)
30
- file = file
31
- elsif file.respond_to? :file
32
- file = File.open(file.file)
33
- elsif file.respond_to? :path
34
- file = File.open(file.path)
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
- raise(ArgumentError, 'Bad File/Stream')
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.respond_to?(:url) || file.respond_to?(:expiring_url)
45
- # expiring_url seems needed for paperclip to work
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 is_io?(file)
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.to_s
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 "passes through" do
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 be file
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
- expect(generator.normalize(file)).to be_a File
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
- let(:file){ Paperclip::Attachment.new(:name, :instance) }
43
- it "creates a File" do
44
- expect(File).to receive(:open).once
45
- generator.normalize(file)
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 "passes through" do
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 be file
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 be file
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.13
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: 2017-05-17 00:00:00.000000000 Z
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.12
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