paperclip-deflater 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b82e5941ea41f9e9d9a7e25a6ffcdd92480cb404
4
+ data.tar.gz: b8c20ec4807349555c5a7e592761a2b4f13ff7b1
5
+ SHA512:
6
+ metadata.gz: 6d2f11aa0a288acf3929d72bc01a5b728b714a53f645734742876d38a484ea67c64acf1392ef0894573e5c4e7defccf95d863998c6cd89e794255eee7e7c0ed1
7
+ data.tar.gz: 49e7fc02bd3dc030477a1f615f941e68decc74a5bea6a655b78d5ae98f906122f4be4379afff8ba78649edd9339577b60831e0d9f5ee790783fe8e53b5a18ab8
data/.gitignore ADDED
@@ -0,0 +1,33 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /log/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ ## Misc
29
+ Gemfile.lock
30
+ gemfiles/*.lock
31
+ .ruby-version
32
+ .ruby-gemset
33
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1
7
+
8
+ env:
9
+ -
10
+ - PAPERCLIP_VERSION=3.0.0
11
+ - PAPERCLIP_VERSION=4.0.0
12
+
13
+ script: "bundle exec rake spec"
14
+
15
+ branches:
16
+ only:
17
+ - master
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "paperclip", "~> #{ENV['PAPERCLIP_VERSION']}" if ENV['PAPERCLIP_VERSION'].to_s != ''
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Daisuke Taniwaki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # paperclip-deflater
2
+
3
+ [![Gem Version][gem-image]][gem-link]
4
+ [![Dependency Status][deps-image]][deps-link]
5
+ [![Build Status][build-image]][build-link]
6
+ [![Coverage Status][cov-image]][cov-link]
7
+ [![Code Climate][gpa-image]][gpa-link]
8
+
9
+ Deflate files in Paperclip before upload.
10
+
11
+ ## Installation
12
+
13
+ Add the paperclip-deflater gem to your Gemfile.
14
+
15
+ ```ruby
16
+ gem "paperclip-deflater"
17
+ ```
18
+
19
+ And run `bundle install`.
20
+
21
+ ## Setup
22
+
23
+ ```ruby
24
+ class Something
25
+ has_attached_file :js,
26
+ s3_metadata: { content_encoding: 'gzip' },
27
+ styles: { gzip: {processors: [:deflater], format: '.gz'} },
28
+ path: "test/:id.:extension:format"
29
+ end
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new [Pull Request](../../pull/new/master)
39
+
40
+ ## Copyright
41
+
42
+ Copyright (c) 2014 Daisuke Taniwaki. See [LICENSE](LICENSE) for details.
43
+
44
+
45
+
46
+
47
+ [gem-image]: https://badge.fury.io/rb/paperclip-deflater.svg
48
+ [gem-link]: http://badge.fury.io/rb/paperclip-deflater
49
+ [build-image]: https://secure.travis-ci.org/dtaniwaki/paperclip-deflater.png
50
+ [build-link]: http://travis-ci.org/dtaniwaki/paperclip-deflater
51
+ [deps-image]: https://gemnasium.com/dtaniwaki/paperclip-deflater.svg
52
+ [deps-link]: https://gemnasium.com/dtaniwaki/paperclip-deflater
53
+ [cov-image]: https://coveralls.io/repos/dtaniwaki/paperclip-deflater/badge.png
54
+ [cov-link]: https://coveralls.io/r/dtaniwaki/paperclip-deflater
55
+ [gpa-image]: https://codeclimate.com/github/dtaniwaki/paperclip-deflater.png
56
+ [gpa-link]: https://codeclimate.com/github/dtaniwaki/paperclip-deflater
57
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,42 @@
1
+ require 'active_model'
2
+ require 'paperclip/processor'
3
+ require 'zlib'
4
+ require 'tempfile'
5
+
6
+ module Paperclip
7
+ module Processors
8
+ class Deflater < ::Paperclip::Processor
9
+ VERSION = ::File.read(::File.expand_path('../../../../VERSION', __FILE__)).to_s.strip
10
+
11
+ def initialize(file, options = {}, attachment = nil)
12
+ super
13
+ @format = @options[:format]
14
+ @deflate_options = @options[:deflate_options] || {}
15
+ @current_format = File.extname(@file.path)
16
+ @basename = File.basename(@file.path, @current_format)
17
+ end
18
+
19
+ def make
20
+ src = @file
21
+
22
+ should_deflate = @attachment.instance_read(:deflate)
23
+ return src if should_deflate == false
24
+
25
+ level = @deflate_options[:level]
26
+ window_bits = @deflate_options[:window_bits]
27
+ memlevel = @deflate_options[:memlevel]
28
+ strategy = @deflate_options[:strategy]
29
+
30
+ dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
31
+ dst.binmode
32
+ zd = Zlib::Deflate.new(level, window_bits, memlevel, strategy)
33
+ dst.write zd.deflate(src.read)
34
+ dst.flush
35
+ dst.rewind
36
+ zd.close
37
+
38
+ dst
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ require 'paperclip/processors/deflater'
2
+
3
+ Paperclip.configure do |c|
4
+ c.register_processor :deflater, Paperclip::Processors::Deflater
5
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../lib/paperclip/processors/deflater', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "paperclip-deflater"
5
+ gem.version = Paperclip::Processors::Deflater::VERSION
6
+ gem.platform = Gem::Platform::RUBY
7
+ gem.authors = ["Daisuke Taniwaki"]
8
+ gem.email = ["daisuketaniwaki@gmail.com"]
9
+ gem.homepage = "https://github.com/dtaniwaki/paperclip-deflater"
10
+ gem.summary = "Deflate Processor for Paperclip"
11
+ gem.description = "Deflate Processor for Paperclip"
12
+ gem.license = "MIT"
13
+
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_dependency "paperclip", ">= 3.0"
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec", ">= 3.0"
23
+ gem.add_development_dependency "coveralls"
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Paperclip::Processors::Deflater do
4
+ let(:attachment) { double }
5
+ let(:should_deflate) { true }
6
+ let(:options) { {} }
7
+ let(:file) { Tempfile.new('paperclip-processors-deflater') }
8
+ subject { Paperclip::Processors::Deflater.new(file, options, attachment) }
9
+ before do
10
+ allow(attachment).to receive(:instance_read).with(:deflate).and_return(should_deflate)
11
+ file.write 'test'
12
+ file.rewind
13
+ end
14
+ it "deflates the file" do
15
+ dst = subject.make
16
+ out = File.open(dst.path).read
17
+ expect(out).to eq("x\x9C")
18
+ end
19
+ context "disable deflate" do
20
+ let(:should_deflate) { false }
21
+ it "does not deflate the file" do
22
+ dst = subject.make
23
+ out = File.open(dst.path).read
24
+ expect(out).to eq("test")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ SimpleCov.start do
7
+ add_filter 'spec/'
8
+ end
9
+
10
+ require 'paperclip-deflater'
11
+
12
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
13
+
14
+ RSpec.configure do |config|
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-deflater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daisuke Taniwaki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paperclip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.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.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.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Deflate Processor for Paperclip
70
+ email:
71
+ - daisuketaniwaki@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - VERSION
83
+ - lib/paperclip-deflater.rb
84
+ - lib/paperclip/processors/deflater.rb
85
+ - paperclip-deflater.gemspec
86
+ - spec/paperclip/processors/deflater_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: https://github.com/dtaniwaki/paperclip-deflater
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: Deflate Processor for Paperclip
112
+ test_files:
113
+ - spec/paperclip/processors/deflater_spec.rb
114
+ - spec/spec_helper.rb