carrierwave-postgresql-table 0.1.0

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: '0873cdce630b258b27a7d62a870287ad2628e302'
4
+ data.tar.gz: 7e9ea222ace5c49b3f7392578b79e9c80209b2ab
5
+ SHA512:
6
+ metadata.gz: ad6c264a57086c050e01211d70e5f40e883a1881ace02bf5c694fe3fd1a6cebcedaddaaa0c6e60314b0a877b0301e707d0423872952347facb71ed45a49fcdba
7
+ data.tar.gz: c5a0f07a08f07ef5ae5770c752a589233e80a0e3fd9dc0197e537dbf127cd0bd89752f6d130a66006cdacf9611adb5bccc16fc72fa8e4ae7df69db0922118d73
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise "carrierwave-0.11-rails-4.2" do
2
+ gem "carrierwave", "~> 0.11.2"
3
+ gem "rails", "~> 4.2.7"
4
+ end
5
+
6
+ appraise "carrierwave-1.0.0-rails-4.2" do
7
+ gem "carrierwave", "~> 1.0.0.beta"
8
+ gem "rails", "~> 4.2.7"
9
+ end
10
+
11
+ appraise "carrierwave-1.0.0-rails-5.0" do
12
+ gem "carrierwave", "~> 1.0.0.beta"
13
+ gem "rails", "~> 5.0.0"
14
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrierwave-postgresql-table.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nick Muerdter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # carrierwave-postgresql-table
2
+
3
+ [![Circle CI](https://circleci.com/gh/GUI/carrierwave-postgresql-table.svg?style=svg)](https://circleci.com/gh/GUI/carrierwave-postgresql-table)
4
+
5
+ A PostgreSQL storage adapter for [CarrierWave](https://github.com/carrierwaveuploader/carrierwave). Files are stored as PostgreSQL [large objects](https://www.postgresql.org/docs/current/static/largeobjects.html).
6
+
7
+ This gem is similar to [carrierwave-postgresql](https://github.com/diogob/carrierwave-postgresql), but differs in how it stores file metadata. This gem uses an extra table to store additional file metadata, allowing it to support multiple CarrierWave [versions](https://github.com/carrierwaveuploader/carrierwave#adding-versions) on a single uploader.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "carrierwave-postgresql-table"
15
+ ```
16
+
17
+ ## Compatibility
18
+
19
+ carrierwave-postgresql-table is tested against the following versions of CarrierWave and Rails:
20
+
21
+ - CarrierWave 0.11
22
+ - CarrierWave 1.0 (beta)
23
+ - Rails 4.2
24
+ - Rails 5.0
25
+
26
+ ## Usage
27
+
28
+ Generate the table to store the file uploads:
29
+
30
+ ```sh
31
+ $ rails generate carrierwave_postgresql_table:migration
32
+ $ rake db:migrate
33
+ ```
34
+
35
+ Adjust your uploader to use the `postgresql_table` storage adapter:
36
+
37
+ ```ruby
38
+ class AvatarUploader < CarrierWave::Uploader::Base
39
+ storage :postgresql_table
40
+
41
+ def store_dir
42
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
43
+ end
44
+ end
45
+ ```
46
+
47
+ An optional Rack application is available to provide an endpoint that will stream your files from PostgreSQL. To enable this endpoint, you can mount it in your `config/routes.rb` file:
48
+
49
+ ```ruby
50
+ Rails.application.routes.draw do
51
+ mount CarrierWave::PostgresqlTable::RackApp.new => "/uploads"
52
+ end
53
+ ```
54
+
55
+ The Rack application can also be combined with other routing functionality. For example, to limit uploads to authenticated users when used with Devise:
56
+
57
+ ```ruby
58
+ Rails.application.routes.draw do
59
+ authenticate :user do
60
+ mount CarrierWave::PostgresqlTable::RackApp.new => "/uploads"
61
+ end
62
+ end
63
+ ```
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/GUI/carrierwave-postgresql-table](https://github.com/GUI/carrierwave-postgresql-table).
74
+
75
+ ## Acknowledgments
76
+
77
+ Hat tip to the people behind [carrierwave-postgresql](https://github.com/diogob/carrierwave-postgresql) and [refile-postgres](https://github.com/krists/refile-postgres), which this code is based on.
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "carrierwave/postgresql/table"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "carrierwave/postgresql_table/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carrierwave-postgresql-table"
8
+ spec.version = CarrierWave::PostgresqlTable::VERSION
9
+ spec.authors = ["Nick Muerdter"]
10
+ spec.email = ["nick.muerdter@nrel.gov"]
11
+
12
+ spec.summary = %q{Store CarrierWave files in PostgreSQL (supporting multiple versions per uploader).}
13
+ spec.homepage = "https://github.com/GUI/carrierwave-postgresql-table"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "activerecord"
24
+ spec.add_dependency "carrierwave"
25
+ spec.add_dependency "pg"
26
+
27
+ spec.add_development_dependency "appraisal", "~> 2.1.0"
28
+ spec.add_development_dependency "database_cleaner", "~> 1.5.3"
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ end
data/circle.yml ADDED
@@ -0,0 +1,11 @@
1
+ dependencies:
2
+ pre:
3
+ - gem install bundler -v "~> 1.13.0"
4
+ post:
5
+ - bundle exec appraisal install
6
+ database:
7
+ override:
8
+ - psql -c "CREATE DATABASE carrierwave_postgresql_table_test;" -U postgres
9
+ test:
10
+ override:
11
+ - bundle exec appraisal rake
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "carrierwave", "~> 0.11.2"
6
+ gem "rails", "~> 4.2.7"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,135 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ carrierwave-postgresql-table (0.1.0)
5
+ activerecord
6
+ carrierwave
7
+ pg
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (4.2.7.1)
13
+ actionpack (= 4.2.7.1)
14
+ actionview (= 4.2.7.1)
15
+ activejob (= 4.2.7.1)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ actionpack (4.2.7.1)
19
+ actionview (= 4.2.7.1)
20
+ activesupport (= 4.2.7.1)
21
+ rack (~> 1.6)
22
+ rack-test (~> 0.6.2)
23
+ rails-dom-testing (~> 1.0, >= 1.0.5)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
+ actionview (4.2.7.1)
26
+ activesupport (= 4.2.7.1)
27
+ builder (~> 3.1)
28
+ erubis (~> 2.7.0)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
+ activejob (4.2.7.1)
32
+ activesupport (= 4.2.7.1)
33
+ globalid (>= 0.3.0)
34
+ activemodel (4.2.7.1)
35
+ activesupport (= 4.2.7.1)
36
+ builder (~> 3.1)
37
+ activerecord (4.2.7.1)
38
+ activemodel (= 4.2.7.1)
39
+ activesupport (= 4.2.7.1)
40
+ arel (~> 6.0)
41
+ activesupport (4.2.7.1)
42
+ i18n (~> 0.7)
43
+ json (~> 1.7, >= 1.7.7)
44
+ minitest (~> 5.1)
45
+ thread_safe (~> 0.3, >= 0.3.4)
46
+ tzinfo (~> 1.1)
47
+ appraisal (2.1.0)
48
+ bundler
49
+ rake
50
+ thor (>= 0.14.0)
51
+ arel (6.0.3)
52
+ builder (3.2.2)
53
+ carrierwave (0.11.2)
54
+ activemodel (>= 3.2.0)
55
+ activesupport (>= 3.2.0)
56
+ json (>= 1.7)
57
+ mime-types (>= 1.16)
58
+ mimemagic (>= 0.3.0)
59
+ concurrent-ruby (1.0.2)
60
+ database_cleaner (1.5.3)
61
+ erubis (2.7.0)
62
+ globalid (0.3.7)
63
+ activesupport (>= 4.1.0)
64
+ i18n (0.7.0)
65
+ json (1.8.3)
66
+ loofah (2.0.3)
67
+ nokogiri (>= 1.5.9)
68
+ mail (2.6.4)
69
+ mime-types (>= 1.16, < 4)
70
+ mime-types (3.1)
71
+ mime-types-data (~> 3.2015)
72
+ mime-types-data (3.2016.0521)
73
+ mimemagic (0.3.2)
74
+ mini_portile2 (2.1.0)
75
+ minitest (5.9.0)
76
+ nokogiri (1.6.8)
77
+ mini_portile2 (~> 2.1.0)
78
+ pkg-config (~> 1.1.7)
79
+ pg (0.19.0)
80
+ pkg-config (1.1.7)
81
+ rack (1.6.4)
82
+ rack-test (0.6.3)
83
+ rack (>= 1.0)
84
+ rails (4.2.7.1)
85
+ actionmailer (= 4.2.7.1)
86
+ actionpack (= 4.2.7.1)
87
+ actionview (= 4.2.7.1)
88
+ activejob (= 4.2.7.1)
89
+ activemodel (= 4.2.7.1)
90
+ activerecord (= 4.2.7.1)
91
+ activesupport (= 4.2.7.1)
92
+ bundler (>= 1.3.0, < 2.0)
93
+ railties (= 4.2.7.1)
94
+ sprockets-rails
95
+ rails-deprecated_sanitizer (1.0.3)
96
+ activesupport (>= 4.2.0.alpha)
97
+ rails-dom-testing (1.0.7)
98
+ activesupport (>= 4.2.0.beta, < 5.0)
99
+ nokogiri (~> 1.6.0)
100
+ rails-deprecated_sanitizer (>= 1.0.1)
101
+ rails-html-sanitizer (1.0.3)
102
+ loofah (~> 2.0)
103
+ railties (4.2.7.1)
104
+ actionpack (= 4.2.7.1)
105
+ activesupport (= 4.2.7.1)
106
+ rake (>= 0.8.7)
107
+ thor (>= 0.18.1, < 2.0)
108
+ rake (10.5.0)
109
+ sprockets (3.7.0)
110
+ concurrent-ruby (~> 1.0)
111
+ rack (> 1, < 3)
112
+ sprockets-rails (3.2.0)
113
+ actionpack (>= 4.0)
114
+ activesupport (>= 4.0)
115
+ sprockets (>= 3.0.0)
116
+ thor (0.19.1)
117
+ thread_safe (0.3.5)
118
+ tzinfo (1.2.2)
119
+ thread_safe (~> 0.1)
120
+
121
+ PLATFORMS
122
+ ruby
123
+
124
+ DEPENDENCIES
125
+ appraisal (~> 2.1.0)
126
+ bundler (~> 1.12)
127
+ carrierwave (~> 0.11.2)
128
+ carrierwave-postgresql-table!
129
+ database_cleaner (~> 1.5.3)
130
+ minitest (~> 5.0)
131
+ rails (~> 4.2.7)
132
+ rake (~> 10.0)
133
+
134
+ BUNDLED WITH
135
+ 1.13.0
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "carrierwave", "~> 1.0.0.beta"
6
+ gem "rails", "~> 4.2.7"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,132 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ carrierwave-postgresql-table (0.1.0)
5
+ activerecord
6
+ carrierwave
7
+ pg
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (4.2.7.1)
13
+ actionpack (= 4.2.7.1)
14
+ actionview (= 4.2.7.1)
15
+ activejob (= 4.2.7.1)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ actionpack (4.2.7.1)
19
+ actionview (= 4.2.7.1)
20
+ activesupport (= 4.2.7.1)
21
+ rack (~> 1.6)
22
+ rack-test (~> 0.6.2)
23
+ rails-dom-testing (~> 1.0, >= 1.0.5)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
+ actionview (4.2.7.1)
26
+ activesupport (= 4.2.7.1)
27
+ builder (~> 3.1)
28
+ erubis (~> 2.7.0)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
+ activejob (4.2.7.1)
32
+ activesupport (= 4.2.7.1)
33
+ globalid (>= 0.3.0)
34
+ activemodel (4.2.7.1)
35
+ activesupport (= 4.2.7.1)
36
+ builder (~> 3.1)
37
+ activerecord (4.2.7.1)
38
+ activemodel (= 4.2.7.1)
39
+ activesupport (= 4.2.7.1)
40
+ arel (~> 6.0)
41
+ activesupport (4.2.7.1)
42
+ i18n (~> 0.7)
43
+ json (~> 1.7, >= 1.7.7)
44
+ minitest (~> 5.1)
45
+ thread_safe (~> 0.3, >= 0.3.4)
46
+ tzinfo (~> 1.1)
47
+ appraisal (2.1.0)
48
+ bundler
49
+ rake
50
+ thor (>= 0.14.0)
51
+ arel (6.0.3)
52
+ builder (3.2.2)
53
+ carrierwave (1.0.0.beta)
54
+ activemodel (>= 4.0.0)
55
+ activesupport (>= 4.0.0)
56
+ mime-types (>= 1.16)
57
+ concurrent-ruby (1.0.2)
58
+ database_cleaner (1.5.3)
59
+ erubis (2.7.0)
60
+ globalid (0.3.7)
61
+ activesupport (>= 4.1.0)
62
+ i18n (0.7.0)
63
+ json (1.8.3)
64
+ loofah (2.0.3)
65
+ nokogiri (>= 1.5.9)
66
+ mail (2.6.4)
67
+ mime-types (>= 1.16, < 4)
68
+ mime-types (3.1)
69
+ mime-types-data (~> 3.2015)
70
+ mime-types-data (3.2016.0521)
71
+ mini_portile2 (2.1.0)
72
+ minitest (5.9.0)
73
+ nokogiri (1.6.8)
74
+ mini_portile2 (~> 2.1.0)
75
+ pkg-config (~> 1.1.7)
76
+ pg (0.19.0)
77
+ pkg-config (1.1.7)
78
+ rack (1.6.4)
79
+ rack-test (0.6.3)
80
+ rack (>= 1.0)
81
+ rails (4.2.7.1)
82
+ actionmailer (= 4.2.7.1)
83
+ actionpack (= 4.2.7.1)
84
+ actionview (= 4.2.7.1)
85
+ activejob (= 4.2.7.1)
86
+ activemodel (= 4.2.7.1)
87
+ activerecord (= 4.2.7.1)
88
+ activesupport (= 4.2.7.1)
89
+ bundler (>= 1.3.0, < 2.0)
90
+ railties (= 4.2.7.1)
91
+ sprockets-rails
92
+ rails-deprecated_sanitizer (1.0.3)
93
+ activesupport (>= 4.2.0.alpha)
94
+ rails-dom-testing (1.0.7)
95
+ activesupport (>= 4.2.0.beta, < 5.0)
96
+ nokogiri (~> 1.6.0)
97
+ rails-deprecated_sanitizer (>= 1.0.1)
98
+ rails-html-sanitizer (1.0.3)
99
+ loofah (~> 2.0)
100
+ railties (4.2.7.1)
101
+ actionpack (= 4.2.7.1)
102
+ activesupport (= 4.2.7.1)
103
+ rake (>= 0.8.7)
104
+ thor (>= 0.18.1, < 2.0)
105
+ rake (10.5.0)
106
+ sprockets (3.7.0)
107
+ concurrent-ruby (~> 1.0)
108
+ rack (> 1, < 3)
109
+ sprockets-rails (3.2.0)
110
+ actionpack (>= 4.0)
111
+ activesupport (>= 4.0)
112
+ sprockets (>= 3.0.0)
113
+ thor (0.19.1)
114
+ thread_safe (0.3.5)
115
+ tzinfo (1.2.2)
116
+ thread_safe (~> 0.1)
117
+
118
+ PLATFORMS
119
+ ruby
120
+
121
+ DEPENDENCIES
122
+ appraisal (~> 2.1.0)
123
+ bundler (~> 1.12)
124
+ carrierwave (~> 1.0.0.beta)
125
+ carrierwave-postgresql-table!
126
+ database_cleaner (~> 1.5.3)
127
+ minitest (~> 5.0)
128
+ rails (~> 4.2.7)
129
+ rake (~> 10.0)
130
+
131
+ BUNDLED WITH
132
+ 1.13.0
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "carrierwave", "~> 1.0.0.beta"
6
+ gem "rails", "~> 5.0.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,137 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ carrierwave-postgresql-table (0.1.0)
5
+ activerecord
6
+ carrierwave
7
+ pg
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (5.0.0.1)
13
+ actionpack (= 5.0.0.1)
14
+ nio4r (~> 1.2)
15
+ websocket-driver (~> 0.6.1)
16
+ actionmailer (5.0.0.1)
17
+ actionpack (= 5.0.0.1)
18
+ actionview (= 5.0.0.1)
19
+ activejob (= 5.0.0.1)
20
+ mail (~> 2.5, >= 2.5.4)
21
+ rails-dom-testing (~> 2.0)
22
+ actionpack (5.0.0.1)
23
+ actionview (= 5.0.0.1)
24
+ activesupport (= 5.0.0.1)
25
+ rack (~> 2.0)
26
+ rack-test (~> 0.6.3)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ actionview (5.0.0.1)
30
+ activesupport (= 5.0.0.1)
31
+ builder (~> 3.1)
32
+ erubis (~> 2.7.0)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
35
+ activejob (5.0.0.1)
36
+ activesupport (= 5.0.0.1)
37
+ globalid (>= 0.3.6)
38
+ activemodel (5.0.0.1)
39
+ activesupport (= 5.0.0.1)
40
+ activerecord (5.0.0.1)
41
+ activemodel (= 5.0.0.1)
42
+ activesupport (= 5.0.0.1)
43
+ arel (~> 7.0)
44
+ activesupport (5.0.0.1)
45
+ concurrent-ruby (~> 1.0, >= 1.0.2)
46
+ i18n (~> 0.7)
47
+ minitest (~> 5.1)
48
+ tzinfo (~> 1.1)
49
+ appraisal (2.1.0)
50
+ bundler
51
+ rake
52
+ thor (>= 0.14.0)
53
+ arel (7.1.2)
54
+ builder (3.2.2)
55
+ carrierwave (1.0.0.beta)
56
+ activemodel (>= 4.0.0)
57
+ activesupport (>= 4.0.0)
58
+ mime-types (>= 1.16)
59
+ concurrent-ruby (1.0.2)
60
+ database_cleaner (1.5.3)
61
+ erubis (2.7.0)
62
+ globalid (0.3.7)
63
+ activesupport (>= 4.1.0)
64
+ i18n (0.7.0)
65
+ loofah (2.0.3)
66
+ nokogiri (>= 1.5.9)
67
+ mail (2.6.4)
68
+ mime-types (>= 1.16, < 4)
69
+ method_source (0.8.2)
70
+ mime-types (3.1)
71
+ mime-types-data (~> 3.2015)
72
+ mime-types-data (3.2016.0521)
73
+ mini_portile2 (2.1.0)
74
+ minitest (5.9.0)
75
+ nio4r (1.2.1)
76
+ nokogiri (1.6.8)
77
+ mini_portile2 (~> 2.1.0)
78
+ pkg-config (~> 1.1.7)
79
+ pg (0.19.0)
80
+ pkg-config (1.1.7)
81
+ rack (2.0.1)
82
+ rack-test (0.6.3)
83
+ rack (>= 1.0)
84
+ rails (5.0.0.1)
85
+ actioncable (= 5.0.0.1)
86
+ actionmailer (= 5.0.0.1)
87
+ actionpack (= 5.0.0.1)
88
+ actionview (= 5.0.0.1)
89
+ activejob (= 5.0.0.1)
90
+ activemodel (= 5.0.0.1)
91
+ activerecord (= 5.0.0.1)
92
+ activesupport (= 5.0.0.1)
93
+ bundler (>= 1.3.0, < 2.0)
94
+ railties (= 5.0.0.1)
95
+ sprockets-rails (>= 2.0.0)
96
+ rails-dom-testing (2.0.1)
97
+ activesupport (>= 4.2.0, < 6.0)
98
+ nokogiri (~> 1.6.0)
99
+ rails-html-sanitizer (1.0.3)
100
+ loofah (~> 2.0)
101
+ railties (5.0.0.1)
102
+ actionpack (= 5.0.0.1)
103
+ activesupport (= 5.0.0.1)
104
+ method_source
105
+ rake (>= 0.8.7)
106
+ thor (>= 0.18.1, < 2.0)
107
+ rake (10.5.0)
108
+ sprockets (3.7.0)
109
+ concurrent-ruby (~> 1.0)
110
+ rack (> 1, < 3)
111
+ sprockets-rails (3.2.0)
112
+ actionpack (>= 4.0)
113
+ activesupport (>= 4.0)
114
+ sprockets (>= 3.0.0)
115
+ thor (0.19.1)
116
+ thread_safe (0.3.5)
117
+ tzinfo (1.2.2)
118
+ thread_safe (~> 0.1)
119
+ websocket-driver (0.6.4)
120
+ websocket-extensions (>= 0.1.0)
121
+ websocket-extensions (0.1.2)
122
+
123
+ PLATFORMS
124
+ ruby
125
+
126
+ DEPENDENCIES
127
+ appraisal (~> 2.1.0)
128
+ bundler (~> 1.12)
129
+ carrierwave (~> 1.0.0.beta)
130
+ carrierwave-postgresql-table!
131
+ database_cleaner (~> 1.5.3)
132
+ minitest (~> 5.0)
133
+ rails (~> 5.0.0)
134
+ rake (~> 10.0)
135
+
136
+ BUNDLED WITH
137
+ 1.13.0
@@ -0,0 +1,7 @@
1
+ require "active_record"
2
+ require "pg"
3
+ require "carrierwave"
4
+ require "carrierwave/storage/postgresql_table"
5
+ require "carrierwave/postgresql_table/rack_app"
6
+
7
+ CarrierWave::Uploader::Base.storage_engines[:postgresql_table] = "CarrierWave::Storage::PostgresqlTable"
@@ -0,0 +1,31 @@
1
+ module CarrierWave
2
+ module PostgresqlTable
3
+ class RackApp
4
+ READ_CHUNK_SIZE = 16384
5
+
6
+ def call(env)
7
+ request = Rack::Request.new(env)
8
+
9
+ file = CarrierWave::Storage::PostgresqlTable::File.new(request.path.sub(/^\//, ""))
10
+
11
+ headers = {
12
+ "Last-Modified" => file.last_modified.httpdate,
13
+ "Content-Type" => file.content_type,
14
+ "Content-Disposition" => "inline",
15
+ }
16
+
17
+ if(request.params["download"] == "true")
18
+ headers["Content-Disposition"] = "attachment; filename=#{file.filename}"
19
+ end
20
+
21
+ body = Enumerator.new do |response_body|
22
+ while(chunk = file.read(READ_CHUNK_SIZE)) do
23
+ response_body << chunk
24
+ end
25
+ end
26
+
27
+ [200, headers, body]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module CarrierWave
2
+ module PostgresqlTable
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,186 @@
1
+ module CarrierWave
2
+ module Storage
3
+ class PostgresqlTable < Abstract
4
+ def store!(file)
5
+ if(uploader.move_to_store && file.kind_of?(CarrierWave::Storage::PostgresqlTable::File))
6
+ file.move_to(uploader.store_path)
7
+ file
8
+ else
9
+ f = CarrierWave::Storage::PostgresqlTable::File.new(uploader.store_path)
10
+ f.store(file)
11
+ f
12
+ end
13
+ end
14
+
15
+ def retrieve!(identifier)
16
+ CarrierWave::Storage::PostgresqlTable::File.new(uploader.store_path(identifier))
17
+ end
18
+
19
+ def cache!(new_file)
20
+ f = CarrierWave::Storage::PostgresqlTable::File.new(uploader.cache_path)
21
+ f.store(new_file)
22
+ f
23
+ end
24
+
25
+ def retrieve_from_cache!(identifier)
26
+ CarrierWave::Storage::PostgresqlTable::File.new(uploader.cache_path(identifier))
27
+ end
28
+
29
+ def delete_dir!(path)
30
+ # This is only supposed to delete *empty* directories, which don't
31
+ # exist in our database.
32
+ end
33
+
34
+ def clean_cache!(seconds)
35
+ time = Time.now - seconds.seconds
36
+ CarrierWaveFile.delete_all_files("updated_at < #{CarrierWaveFile.sanitize(time)}")
37
+ end
38
+
39
+ class CarrierWaveFile < ::ActiveRecord::Base
40
+ self.table_name = "carrierwave_files"
41
+
42
+ def self.delete_all_files(conditions)
43
+ self.transaction do
44
+ self.connection.execute("SELECT lo_unlink(pg_largeobject_oid) FROM (SELECT DISTINCT pg_largeobject_oid FROM #{self.table_name} WHERE #{conditions}) AS oids")
45
+ self.where(conditions).delete_all
46
+ end
47
+ end
48
+ end
49
+
50
+ class File
51
+ READ_CHUNK_SIZE = 16384
52
+ STREAM_CHUNK_SIZE = 16384
53
+
54
+ attr_reader :path
55
+
56
+ def initialize(path)
57
+ @path = path
58
+ @record = CarrierWaveFile.find_or_initialize_by(:path => path)
59
+ @read_pos = 0
60
+ end
61
+
62
+ def read(length = nil, buffer = nil)
63
+ data = nil
64
+ CarrierWaveFile.transaction do
65
+ raw_connection = CarrierWaveFile.connection.raw_connection
66
+
67
+ begin
68
+ lo = raw_connection.lo_open(@record.pg_largeobject_oid)
69
+ if(length)
70
+ raw_connection.lo_lseek(lo, @read_pos, PG::SEEK_SET)
71
+ data = raw_connection.lo_read(lo, length)
72
+ @read_pos = raw_connection.lo_tell(lo)
73
+ else
74
+ data = raw_connection.lo_read(lo, size)
75
+ end
76
+ ensure
77
+ raw_connection.lo_close(lo) if(lo)
78
+ end
79
+ end
80
+
81
+ if(buffer && data)
82
+ buffer.replace(data)
83
+ end
84
+
85
+ data
86
+ end
87
+
88
+ def to_tempfile
89
+ Tempfile.new(:binmode => true).tap do |tempfile|
90
+ IO.copy_stream(self, tempfile)
91
+ tempfile.rewind
92
+ tempfile.fsync
93
+ end
94
+ end
95
+
96
+ def filename
97
+ ::File.basename(@path)
98
+ end
99
+
100
+ def last_modified
101
+ @record.updated_at
102
+ end
103
+
104
+ def size
105
+ @record.size
106
+ end
107
+
108
+ def content_type
109
+ @record.content_type
110
+ end
111
+
112
+ def content_type=(new_content_type)
113
+ @record.update_attribute(:content_type, new_content_type)
114
+ end
115
+
116
+ def url(options = {})
117
+ ::File.join("/", @path)
118
+ end
119
+
120
+ def store(new_file)
121
+ CarrierWaveFile.transaction do
122
+ oid = nil
123
+ if(new_file.kind_of?(CarrierWave::Storage::PostgresqlTable::File))
124
+ oid = new_file.copy_to(@path)
125
+ else
126
+ raw_connection = CarrierWaveFile.connection.raw_connection
127
+ file = new_file.to_file
128
+
129
+ begin
130
+ oid = @record.pg_largeobject_oid || raw_connection.lo_creat
131
+ handle = raw_connection.lo_open(oid, PG::INV_WRITE)
132
+ raw_connection.lo_truncate(handle, 0)
133
+ buffer = ""
134
+ until file.eof?
135
+ file.read(READ_CHUNK_SIZE, buffer)
136
+ raw_connection.lo_write(handle, buffer)
137
+ end
138
+ file.close
139
+ ensure
140
+ raw_connection.lo_close(handle)
141
+ end
142
+ end
143
+
144
+ begin
145
+ @record.pg_largeobject_oid = oid
146
+ @record.size = new_file.size
147
+ @record.content_type = new_file.content_type
148
+ @record.save
149
+ rescue ::ActiveRecord::RecordNotUnique
150
+ @record = CarrierWaveFile.find_or_initialize_by(:path => @path)
151
+ retry
152
+ end
153
+ end
154
+ end
155
+
156
+ def copy_to(new_path)
157
+ CarrierWaveFile.transaction do
158
+ connection = CarrierWaveFile.connection
159
+
160
+ result = connection.execute("INSERT INTO pg_largeobject_metadata(lomowner, lomacl)
161
+ SELECT lomowner, lomacl
162
+ FROM pg_largeobject_metadata
163
+ WHERE oid = #{CarrierWaveFile.sanitize(@record.pg_largeobject_oid)}
164
+ RETURNING oid AS new_oid")
165
+ new_oid = Integer(result.values[0][0])
166
+
167
+ connection.execute("INSERT INTO pg_largeobject(loid, pageno, data)
168
+ SELECT #{new_oid}, pageno, data
169
+ FROM pg_largeobject
170
+ WHERE loid = #{CarrierWaveFile.sanitize(@record.pg_largeobject_oid)}")
171
+
172
+ new_oid
173
+ end
174
+ end
175
+
176
+ def move_to(new_path)
177
+ @record.update_attribute(:path, new_path)
178
+ end
179
+
180
+ def delete
181
+ CarrierWaveFile.delete_all_files("id = #{CarrierWaveFile.sanitize(@record.id)}")
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates database migration for table to store list of uploads
3
+
4
+ Example:
5
+ rails generate carrierwave_postgresql_table:migration
6
+
7
+ This will create:
8
+ db/migrate/<timestamp>_create_carrierwave_files.rb
@@ -0,0 +1,16 @@
1
+ require "rails/generators/active_record"
2
+
3
+ module CarrierwavePostgresqlTable
4
+ class MigrationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ source_root(File.expand_path("../templates", __FILE__))
7
+
8
+ def self.next_migration_number(dirname)
9
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
10
+ end
11
+
12
+ def create_migration_file
13
+ migration_template("migration.rb.erb", "db/migrate/create_carrierwave_files.rb")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class CreateCarrierwaveFiles < ActiveRecord::Migration
2
+ def up
3
+ create_table :carrierwave_files do |t|
4
+ t.column :path, :string, :null => false
5
+ t.column :pg_largeobject_oid, :oid, :null => false
6
+ t.column :size, :integer, :null => false
7
+ t.column :content_type, :string
8
+ t.timestamps(:null => false)
9
+ end
10
+ add_index :carrierwave_files, :path, :unique => true
11
+ end
12
+
13
+ def down
14
+ drop_table :carrierwave_files
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-postgresql-table
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick Muerdter
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: carrierwave
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: pg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: appraisal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.5.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.5.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '5.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '5.0'
125
+ description:
126
+ email:
127
+ - nick.muerdter@nrel.gov
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Appraisals
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - bin/console
139
+ - bin/setup
140
+ - carrierwave-postgresql-table.gemspec
141
+ - circle.yml
142
+ - gemfiles/carrierwave_0.11_rails_4.2.gemfile
143
+ - gemfiles/carrierwave_0.11_rails_4.2.gemfile.lock
144
+ - gemfiles/carrierwave_1.0.0_rails_4.2.gemfile
145
+ - gemfiles/carrierwave_1.0.0_rails_4.2.gemfile.lock
146
+ - gemfiles/carrierwave_1.0.0_rails_5.0.gemfile
147
+ - gemfiles/carrierwave_1.0.0_rails_5.0.gemfile.lock
148
+ - lib/carrierwave-postgresql-table.rb
149
+ - lib/carrierwave/postgresql_table/rack_app.rb
150
+ - lib/carrierwave/postgresql_table/version.rb
151
+ - lib/carrierwave/storage/postgresql_table.rb
152
+ - lib/generators/carrierwave_postgresql_table/migration/USAGE
153
+ - lib/generators/carrierwave_postgresql_table/migration/migration_generator.rb
154
+ - lib/generators/carrierwave_postgresql_table/migration/templates/migration.rb.erb
155
+ homepage: https://github.com/GUI/carrierwave-postgresql-table
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.5.1
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Store CarrierWave files in PostgreSQL (supporting multiple versions per uploader).
179
+ test_files: []