paperclip-rack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86bfeddcc94987c7a007e80567859a83f60a4fd9
4
+ data.tar.gz: 54051f2be46568e2e2d46d7b692fba5fd1835502
5
+ SHA512:
6
+ metadata.gz: 819f9fdb2cf2a9079245956c6d28e9f88f205c864e2b69ae903ca7741ec521839304c7ecca14bcaffd61b4ac86e5c86e98df322cd55ee5dd71e07bb41e64c4a7
7
+ data.tar.gz: 6cc9ebccc4f682d4ce16eb10fdfaaaf2247ac44e58e2ec95494df2e2d11aa77a3fe226348f2a4824da579f255ceddde16cae385302c09e5824fecac24a31878c
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - rbx-18mode
6
+ - rbx-19mode
7
+ - ruby-head
8
+ - 1.8.7
9
+ - 2.0.0
10
+ - jruby-18mode
11
+ - jruby-19mode
12
+ - jruby-head
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: 1.9.2
16
+ - rvm: 1.8.7
17
+ - rvm: rbx-18mode
18
+ - rvm: ruby-head
19
+ - rvm: jruby-18mode
20
+ - rvm: jruby-head
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paperclip-rack.gemspec
4
+ gemspec
5
+
6
+ gem 'pry', :platform => :ruby
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tatsuo Kaniwa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Paperclip::Rack
2
+
3
+ Enable paperclip file upload on Non-Rails rack application such as Sinatra
4
+
5
+ ## Installation
6
+
7
+ Add 'include Paperclip::Glue' to your model
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'paperclip-rack', require: 'paperclip/rack'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install paperclip-rack
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+
5
+ desc "default task"
6
+ task :default => [:test]
7
+
8
+ desc 'Test'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.pattern = "test/**/*_test.rb"
11
+ t.verbose = true
12
+ end
@@ -0,0 +1,3 @@
1
+ require "paperclip"
2
+ require "paperclip/rack/version"
3
+ require "paperclip/rack/io_adapters/file_adapter"
@@ -0,0 +1,30 @@
1
+ module Paperclip
2
+ module Rack
3
+ class FileAdapter < ::Paperclip::AbstractAdapter
4
+ def initialize(target)
5
+ @target = target[:tempfile]
6
+ cache_current_values(target)
7
+ end
8
+
9
+ private
10
+
11
+ def cache_current_values(target)
12
+ self.original_filename = target[:filename] if target.has_key?(:filename)
13
+ self.original_filename ||= @target.original_filename if @target.respond_to?(:original_filename)
14
+ self.original_filename ||= File.basename(@target.path)
15
+ @tempfile = copy_to_tempfile(@target)
16
+ @content_type = Paperclip::ContentTypeDetector.new(@target.path).detect
17
+ @size = File.size(@target)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
24
+ Paperclip.io_adapters.register Paperclip::Rack::FileAdapter do |target|
25
+ begin
26
+ target.is_a?(Hash) && Tempfile === target[:tempfile]
27
+ rescue => e
28
+ false
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Paperclip
2
+ module Rack
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'paperclip/rack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "paperclip-rack"
8
+ spec.version = Paperclip::Rack::VERSION
9
+ spec.authors = ["Tatsuo Kaniwa"]
10
+ spec.email = ["tatsuo@kaniwa.biz"]
11
+ spec.description = %q{Enable paperclip file upload on Non-Rails rack application such as Sinatra}
12
+ spec.summary = %q{Enable paperclip file upload on Non-Rails rack application}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency("paperclip", "~> 3.0")
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "shoulda"
26
+ spec.add_development_dependency "rack"
27
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "rubygems"
2
+ require "tempfile"
3
+ require "pathname"
4
+ require "test/unit"
5
+ require "shoulda"
6
+ require "shoulda/context"
7
+ require "mime/types"
8
+ require "rack/utils"
9
+ require "rack/mock"
10
+
11
+ begin
12
+ require "pry"
13
+ rescue LoadError
14
+ # Pry is not available, just ignore.
15
+ end
16
+
17
+ ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), "..")))
18
+
19
+ require File.join(ROOT, "lib", "paperclip", "rack")
20
+
21
+ def multipart_fixture(name, boundary = "AaB03x")
22
+ file = multipart_file(name)
23
+ data = File.open(file, 'rb') { |io| io.read }
24
+
25
+ type = "multipart/form-data; boundary=#{boundary}"
26
+ length = data.respond_to?(:bytesize) ? data.bytesize : data.size
27
+
28
+ { "CONTENT_TYPE" => type,
29
+ "CONTENT_LENGTH" => length.to_s,
30
+ :input => StringIO.new(data) }
31
+ end
32
+
33
+ def multipart_file(name)
34
+ File.join(File.dirname(__FILE__), "multipart", name.to_s)
35
+ end
@@ -0,0 +1,44 @@
1
+ require "./test/helper"
2
+
3
+ class FileAdapterTest < Test::Unit::TestCase
4
+
5
+ context "rack multipart" do
6
+ context "binary file" do
7
+ setup do
8
+ env = Rack::MockRequest.env_for("/", multipart_fixture(:binary))
9
+ target = Rack::Multipart.parse_multipart(env)
10
+ @subject = Paperclip.io_adapters.for(target["files"])
11
+ end
12
+
13
+ should "provide correct mime-type" do
14
+ assert_equal "image/png", @subject.content_type
15
+ end
16
+ end
17
+
18
+ context "text file" do
19
+ setup do
20
+ env = Rack::MockRequest.env_for("/", multipart_fixture(:text))
21
+ target = Rack::Multipart.parse_multipart(env)
22
+ @subject = Paperclip.io_adapters.for(target["files"])
23
+ end
24
+
25
+ should "provide correct mime-type" do
26
+ assert_equal "text/plain", @subject.content_type
27
+ end
28
+ end
29
+
30
+ context "empty file" do
31
+ setup do
32
+ env = Rack::MockRequest.env_for("/", multipart_fixture(:empty))
33
+ target = Rack::Multipart.parse_multipart(env)
34
+ @subject = Paperclip.io_adapters.for(target["files"])
35
+ end
36
+
37
+ should "provide correct mime-type" do
38
+ assert_match %r{.*/x-empty}, @subject.content_type
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
Binary file
@@ -0,0 +1,10 @@
1
+ --AaB03x
2
+ Content-Disposition: form-data; name="submit-name"
3
+
4
+ Larry
5
+ --AaB03x
6
+ Content-Disposition: form-data; name="files"; filename="file1.txt"
7
+ Content-Type: text/plain
8
+
9
+
10
+ --AaB03x--
@@ -0,0 +1,15 @@
1
+ --AaB03x
2
+ Content-Disposition: form-data; name="submit-name"
3
+
4
+ Larry
5
+ --AaB03x
6
+ Content-Disposition: form-data; name="submit-name-with-content"
7
+ Content-Type: text/plain
8
+
9
+ Berry
10
+ --AaB03x
11
+ Content-Disposition: form-data; name="files"; filename="file1.txt"
12
+ Content-Type: text/plain
13
+
14
+ contents
15
+ --AaB03x--
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-rack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tatsuo Kaniwa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-10 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: bundler
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: shoulda
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
+ - !ruby/object:Gem::Dependency
70
+ name: rack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Enable paperclip file upload on Non-Rails rack application such as Sinatra
84
+ email:
85
+ - tatsuo@kaniwa.biz
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/paperclip/rack.rb
97
+ - lib/paperclip/rack/io_adapters/file_adapter.rb
98
+ - lib/paperclip/rack/version.rb
99
+ - paperclip-rack.gemspec
100
+ - test/helper.rb
101
+ - test/io_adapters/file_adapter_test.rb
102
+ - test/multipart/binary
103
+ - test/multipart/empty
104
+ - test/multipart/text
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.3
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Enable paperclip file upload on Non-Rails rack application
129
+ test_files:
130
+ - test/helper.rb
131
+ - test/io_adapters/file_adapter_test.rb
132
+ - test/multipart/binary
133
+ - test/multipart/empty
134
+ - test/multipart/text
135
+ has_rdoc: