paperclip-deflater 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49bed0decc83cf5c31363c8157336688cad43572
4
- data.tar.gz: b7422ea22f63a8bf21734bfbfa97093e325d40c3
3
+ metadata.gz: 936994b83a0f58ce48c80d843df09abd36dd8a16
4
+ data.tar.gz: fd5e0814a4e0d5e760dc8fe6febffcfc9762e6a6
5
5
  SHA512:
6
- metadata.gz: 3beb013f2adebd189bf8b5e0e9dc162b83c2a29b0caf228bded75a9c04a6b6d52db4847400fc0ba6cd5b374a319cc056d06084ed76b4b5ddbb18ce543272d90c
7
- data.tar.gz: 5be6bef8b0bf9b82181195598cc953e3171fd7d950f487270ff4d407a2af4b247f144787f3a8725a35ae3d9c1cae8904efb99f9bc71f64de7d00786c6253538d
6
+ metadata.gz: dd26871ffed60ec9eea0c37f904cb07cfd3488bb6bc22e142a29e79620722f20484b4ba40397b3af04d6594ee8f55a3b63677ae26746fe5fcf456d9516721cf8
7
+ data.tar.gz: ab704c08c39eef4572b9064ff217043b21630a6a5b7335c1076d9280c9e695e88dc34d465620c9b302df3f6fc4125b32782bc61a07b1dd96df055bf85fa03428
data/README.md CHANGED
@@ -29,6 +29,10 @@ class Something
29
29
  end
30
30
  ```
31
31
 
32
+ ## Per instance turn-off flag
33
+
34
+ If the instance (`xx`) has `xx_no_deflate` method and it returns `true`, you can disable the deflating for the attachment.
35
+
32
36
  ## Contributing
33
37
 
34
38
  1. Fork it
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -13,7 +13,7 @@ module Paperclip
13
13
  end
14
14
 
15
15
  def make
16
- return @file if @attachment.instance_read(:deflate) == false
16
+ return @file if @attachment.instance_read(:no_deflate) == true
17
17
  make_impl
18
18
  end
19
19
 
@@ -2,16 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe Paperclip::Processors::DeflaterBase do
4
4
  let(:attachment) { double }
5
- let(:should_deflate) { true }
5
+ let(:no_deflate) { nil }
6
6
  let(:options) { {} }
7
7
  let(:file) { test_file }
8
8
  subject { Paperclip::Processors::DeflaterBase.new(file, options, attachment) }
9
9
  before do
10
- allow(attachment).to receive(:instance_read).with(:deflate).and_return(should_deflate)
10
+ allow(attachment).to receive(:instance_read).with(:no_deflate).and_return(no_deflate)
11
11
  end
12
12
  describe "#make" do
13
- context "deflate setting is false" do
14
- let(:should_deflate) { false }
13
+ context "no_deflate setting is true" do
14
+ let(:no_deflate) { true }
15
15
  it "returns original" do
16
16
  expect(subject.make).to eq(file)
17
17
  end
@@ -3,19 +3,27 @@ require 'spec_helper'
3
3
 
4
4
  describe Paperclip::Processors::Deflater do
5
5
  let(:attachment) { double }
6
- let(:should_deflate) { true }
7
6
  let(:options) { {} }
8
7
  let(:file) { test_file }
9
8
  subject { Paperclip::Processors::Deflater.new(file, options, attachment) }
10
9
  before do
11
- allow(attachment).to receive(:instance_read).with(:deflate).and_return(should_deflate)
10
+ allow(attachment).to receive(:instance_read).with(:no_deflate)
12
11
  end
13
12
  describe "private methods" do
14
13
  describe "#make_impl" do
15
- it "deflates the file" do
16
- dst = subject.make
17
- data = dst.read
18
- expect(data.unpack('H*').first).to eq("x\x9C".unpack('H*').first)
14
+ shared_examples "deflate" do
15
+ it "deflates the file" do
16
+ dst = subject.make
17
+ data = dst.read
18
+ expect(data.unpack('H*').first).to eq(result.unpack('H*').first)
19
+ end
20
+ end
21
+ let(:result) { "x\x9C" }
22
+ include_examples "deflate"
23
+ context "level gzip_options" do
24
+ let(:result) { "x\xDA" }
25
+ let(:options) { {deflate_options: {level: Zlib::BEST_COMPRESSION}} }
26
+ include_examples "deflate"
19
27
  end
20
28
  end
21
29
  end
@@ -3,24 +3,30 @@ require 'spec_helper'
3
3
 
4
4
  describe Paperclip::Processors::Gzip do
5
5
  let(:attachment) { double }
6
- let(:should_deflate) { true }
7
6
  let(:options) { {} }
8
7
  let(:file) { test_file }
9
8
  subject { Paperclip::Processors::Gzip.new(file, options, attachment) }
10
9
  before do
11
- allow(attachment).to receive(:instance_read).with(:deflate).and_return(should_deflate)
10
+ allow(attachment).to receive(:instance_read).with(:no_deflate)
12
11
  end
13
12
  describe "private methods" do
14
13
  describe "#make_impl" do
15
- before do
16
- allow(file).to receive(:mtime).and_return(Time.new(2000, 1, 2, 3, 4, 5))
14
+ shared_examples "deflate" do
15
+ it "deflates the file" do
16
+ dst = subject.make
17
+ data = dst.read
18
+ expect(data[0..3]).to eq(result1)
19
+ # data[4..7] is modified time and it changes
20
+ expect(data[8..-1]).to eq(result2)
21
+ end
17
22
  end
18
- it "deflates the file" do
19
- dst = subject.make
20
- data = dst.read
21
- expect(data[0..3]).to eq("\u001F\x8B\b\u0000")
22
- # data[4..7] is modified time and it changes
23
- expect(data[8..-1]).to eq("\u0000\u0003+I-.\xE1\u0002\u0000\xC65\xB9;\u0005\u0000\u0000\u0000")
23
+ let(:result1) { "\u001F\x8B\b\u0000" }
24
+ let(:result2) { "\u0000\u0003+I-.\xE1\u0002\u0000\xC65\xB9;\u0005\u0000\u0000\u0000" }
25
+ include_examples "deflate"
26
+ context "level gzip_options" do
27
+ let(:result2) { "\u0002\u0003+I-.\xE1\u0002\u0000\xC65\xB9;\u0005\u0000\u0000\u0000" }
28
+ let(:options) { {gzip_options: {level: Zlib::BEST_COMPRESSION}} }
29
+ include_examples "deflate"
24
30
  end
25
31
  end
26
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-deflater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Taniwaki