mongoid-paperclip 0.0.11 → 0.1.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 +5 -5
- data/.gitignore +1 -0
- data/Gemfile.lock +49 -52
- data/README.md +20 -9
- data/lib/mongoid_paperclip.rb +11 -10
- data/mongoid-paperclip.gemspec +7 -10
- data/spec/mongoid-paperclip_spec.rb +12 -0
- data/spec/spec_helper.rb +18 -3
- metadata +15 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ab6e33f7deca617d928cc8ed4d1faf9c5dd50fbeff677a27bd6cba978c8d332
|
4
|
+
data.tar.gz: ef2b218581e0bc51f271b8b3fb15d10b21521b63e8c848c07a62f344024e735b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0b4c8f32487dcfc459bea442d8308f80b3d793eab6a3fb9fa25eb4e4fef68cd11a8a61bd56fde001762a54fc510f2e3a763c72c1c193030b58955d205fe0545
|
7
|
+
data.tar.gz: ce9af4d226b37e5fe657a36d9c53939ee6d9ca3473b238e6f60ab05266deff6483cee58b9da1cadff142c8e0a630149b45cf9b5713b7a034f871dc5626d89ede
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,67 +1,64 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongoid-paperclip (0.0
|
4
|
+
mongoid-paperclip (0.1.0)
|
5
|
+
kt-paperclip
|
5
6
|
mongoid
|
6
|
-
paperclip (>= 2.3.6, != 4.3.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (4.
|
12
|
-
activesupport (= 4.
|
13
|
-
|
14
|
-
|
15
|
-
i18n (
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
diff-lcs (1.2.5)
|
27
|
-
i18n (0.7.0)
|
28
|
-
json (1.8.3)
|
29
|
-
mime-types (3.1)
|
30
|
-
mime-types-data (~> 3.2015)
|
31
|
-
mime-types-data (3.2016.0521)
|
32
|
-
mimemagic (0.3.2)
|
33
|
-
minitest (5.9.0)
|
34
|
-
mongo (2.2.5)
|
35
|
-
bson (~> 4.0)
|
36
|
-
mongoid (5.1.3)
|
37
|
-
activemodel (~> 4.0)
|
38
|
-
mongo (~> 2.1)
|
39
|
-
origin (~> 2.2)
|
40
|
-
tzinfo (>= 0.3.37)
|
41
|
-
origin (2.2.0)
|
42
|
-
paperclip (5.0.0)
|
11
|
+
activemodel (6.1.4.4)
|
12
|
+
activesupport (= 6.1.4.4)
|
13
|
+
activesupport (6.1.4.4)
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
minitest (>= 5.1)
|
17
|
+
tzinfo (~> 2.0)
|
18
|
+
zeitwerk (~> 2.3)
|
19
|
+
bson (4.13.0)
|
20
|
+
climate_control (0.2.0)
|
21
|
+
concurrent-ruby (1.1.9)
|
22
|
+
diff-lcs (1.5.0)
|
23
|
+
i18n (1.8.11)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
kt-paperclip (7.0.1)
|
43
26
|
activemodel (>= 4.2.0)
|
44
27
|
activesupport (>= 4.2.0)
|
45
|
-
|
28
|
+
marcel (~> 1.0.1)
|
46
29
|
mime-types
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
30
|
+
terrapin (~> 0.6.0)
|
31
|
+
marcel (1.0.2)
|
32
|
+
mime-types (3.4.1)
|
33
|
+
mime-types-data (~> 3.2015)
|
34
|
+
mime-types-data (3.2022.0105)
|
35
|
+
minitest (5.15.0)
|
36
|
+
mongo (2.17.0)
|
37
|
+
bson (>= 4.8.2, < 5.0.0)
|
38
|
+
mongoid (7.3.3)
|
39
|
+
activemodel (>= 5.1, < 6.2)
|
40
|
+
mongo (>= 2.10.5, < 3.0.0)
|
41
|
+
ruby2_keywords (~> 0.0.5)
|
42
|
+
rake (13.0.6)
|
43
|
+
rspec (3.10.0)
|
44
|
+
rspec-core (~> 3.10.0)
|
45
|
+
rspec-expectations (~> 3.10.0)
|
46
|
+
rspec-mocks (~> 3.10.0)
|
47
|
+
rspec-core (3.10.1)
|
48
|
+
rspec-support (~> 3.10.0)
|
49
|
+
rspec-expectations (3.10.1)
|
56
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
-
rspec-support (~> 3.
|
58
|
-
rspec-mocks (3.
|
51
|
+
rspec-support (~> 3.10.0)
|
52
|
+
rspec-mocks (3.10.2)
|
59
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.
|
61
|
-
rspec-support (3.
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
rspec-support (~> 3.10.0)
|
55
|
+
rspec-support (3.10.3)
|
56
|
+
ruby2_keywords (0.0.5)
|
57
|
+
terrapin (0.6.0)
|
58
|
+
climate_control (>= 0.0.3, < 1.0)
|
59
|
+
tzinfo (2.0.4)
|
60
|
+
concurrent-ruby (~> 1.0)
|
61
|
+
zeitwerk (2.5.3)
|
65
62
|
|
66
63
|
PLATFORMS
|
67
64
|
ruby
|
@@ -73,4 +70,4 @@ DEPENDENCIES
|
|
73
70
|
rspec
|
74
71
|
|
75
72
|
BUNDLED WITH
|
76
|
-
|
73
|
+
2.2.31
|
data/README.md
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
# Mongoid::Paperclip
|
2
2
|
|
3
|
-
Integrate [
|
3
|
+
Integrate [kt-paperclip](https://github.com/kreeti/kt-paperclip) into [Mongoid](http://mongoid.org/).
|
4
|
+
(Kt-paperclip is a maintained fork of the original [Paperclip](https://github.com/thoughtbot/paperclip) that is now deprecated)
|
4
5
|
|
5
|
-
This is actually easier and faster to set up than when using Paperclip and the ActiveRecord ORM.
|
6
|
+
This is actually easier and faster to set up than when using Paperclip and the ActiveRecord ORM.
|
6
7
|
|
7
8
|
## Setting it up
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
**Rails.root/Gemfile - Just define the following:**
|
10
|
+
**Gemfile**
|
12
11
|
|
13
12
|
```rb
|
14
|
-
gem "mongoid-paperclip"
|
15
|
-
gem 'aws-sdk', '~> 1.3.4'
|
13
|
+
gem "mongoid-paperclip"
|
16
14
|
```
|
17
15
|
|
18
16
|
Next let's assume we have a User model and we want to allow our users to upload an avatar.
|
@@ -30,7 +28,7 @@ end
|
|
30
28
|
|
31
29
|
## That's it
|
32
30
|
|
33
|
-
That's all you have to do. Users can now upload avatars. Unlike ActiveRecord, Mongoid doesn't use migrations, so we don't need to define the Paperclip columns in a separate file. Invoking
|
31
|
+
That's all you have to do. Users can now upload avatars. Unlike ActiveRecord, Mongoid doesn't use migrations, so we don't need to define the Paperclip columns in a separate file. Invoking `has_mongoid_attached_file` will automatically define the necessary `:avatar` fields for you.
|
34
32
|
|
35
33
|
|
36
34
|
## A more complex example
|
@@ -84,6 +82,19 @@ end
|
|
84
82
|
@user.update_attributes({ ... :pictures => [...] })
|
85
83
|
```
|
86
84
|
|
85
|
+
## Optional fingerprinting
|
86
|
+
|
87
|
+
Paperclip will skip calculating the fingerprint of a file when the `{file}_fingerprint` field is missing from the model. This can be desirable if attaching large files to a model. To disable adding the fingerprint field pass the `disable_fingerprint` option as in this example:
|
88
|
+
|
89
|
+
```rb
|
90
|
+
class User
|
91
|
+
include Mongoid::Document
|
92
|
+
include Mongoid::Paperclip
|
93
|
+
|
94
|
+
has_mongoid_attached_file :usage_report, disable_fingerprint: true
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
87
98
|
## Testing
|
88
99
|
|
89
100
|
If you want to help develop this plugin, clone the repo and bundle to get all dependencies.
|
@@ -98,7 +109,7 @@ rspec
|
|
98
109
|
|
99
110
|
Quite a lot of people have been looking for a solution to use Paperclip with Mongoid so I hope this helps!
|
100
111
|
|
101
|
-
If you need more information on either [Mongoid](http://mongoid.org/) or [
|
112
|
+
If you need more information on either [Mongoid](http://mongoid.org/) or [kt-paperclip](https://github.com/kreeti/kt-paperclip) I suggest checking our their official documentation and website.
|
102
113
|
|
103
114
|
## License
|
104
115
|
|
data/lib/mongoid_paperclip.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
begin
|
4
|
-
require "paperclip"
|
5
|
-
rescue LoadError
|
6
|
-
puts "Mongoid::Paperclip requires that you install the Paperclip gem."
|
7
|
-
exit
|
8
|
-
end
|
1
|
+
require 'paperclip'
|
9
2
|
|
10
3
|
##
|
11
4
|
# the id of mongoid is not integer, correct the id_partitioin.
|
12
5
|
Paperclip.interpolates :id_partition do |attachment, style|
|
13
|
-
attachment.instance.id
|
6
|
+
case id = attachment.instance.id
|
7
|
+
when Integer
|
8
|
+
("%09d".freeze % id).scan(/\d{3}/).join("/".freeze)
|
9
|
+
when String
|
10
|
+
id.scan(/.{4}/).join("/".freeze)
|
11
|
+
else
|
12
|
+
nil
|
13
|
+
end
|
14
14
|
end
|
15
15
|
|
16
16
|
##
|
@@ -89,6 +89,7 @@ module Mongoid
|
|
89
89
|
# it'll also add the required fields for Paperclip since MongoDB is schemaless and doesn't
|
90
90
|
# have migrations.
|
91
91
|
def has_mongoid_attached_file(field, options = {})
|
92
|
+
disable_fingerprint = options.delete(:disable_fingerprint)
|
92
93
|
|
93
94
|
##
|
94
95
|
# Include Paperclip and Paperclip::Glue for compatibility
|
@@ -108,7 +109,7 @@ module Mongoid
|
|
108
109
|
field(:"#{field}_content_type", :type => String)
|
109
110
|
field(:"#{field}_file_size", :type => Integer)
|
110
111
|
field(:"#{field}_updated_at", :type => DateTime)
|
111
|
-
field(:"#{field}_fingerprint", :type => String)
|
112
|
+
field(:"#{field}_fingerprint", :type => String) unless disable_fingerprint
|
112
113
|
end
|
113
114
|
|
114
115
|
##
|
data/mongoid-paperclip.gemspec
CHANGED
@@ -1,23 +1,20 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
Gem::Specification.new do |gem|
|
4
|
-
|
5
2
|
gem.name = 'mongoid-paperclip'
|
6
|
-
gem.version = '0.0
|
3
|
+
gem.version = '0.1.0'
|
7
4
|
gem.platform = Gem::Platform::RUBY
|
8
|
-
gem.authors = 'Michael van Rooijen'
|
9
|
-
gem.email = 'michael@vanrooijen.io'
|
10
|
-
gem.homepage = 'https://github.com/
|
5
|
+
gem.authors = ['Michael van Rooijen', 'Joost Baaij']
|
6
|
+
gem.email = ['michael@vanrooijen.io', 'joost@spacebabies.nl']
|
7
|
+
gem.homepage = 'https://github.com/mrrooijen/mongoid-paperclip'
|
11
8
|
gem.summary = 'Paperclip compatibility for Mongoid ODM for MongoDB.'
|
12
9
|
gem.description = 'Enables you to use Paperclip with the Mongoid ODM for MongoDB.'
|
13
10
|
gem.license = 'MIT'
|
14
11
|
|
15
|
-
gem.files =
|
16
|
-
gem.test_files =
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
17
14
|
gem.require_path = 'lib'
|
18
15
|
|
16
|
+
gem.add_dependency 'kt-paperclip'
|
19
17
|
gem.add_dependency 'mongoid'
|
20
|
-
gem.add_dependency 'paperclip', ['>= 2.3.6', '!=4.3.0']
|
21
18
|
|
22
19
|
gem.add_development_dependency 'bundler'
|
23
20
|
gem.add_development_dependency 'rake'
|
@@ -38,4 +38,16 @@ RSpec.describe Mongoid::Paperclip, type: :unit do
|
|
38
38
|
expect(user.icon_file_name).to eq("avatar.png")
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe "disable fingerprint" do
|
43
|
+
let(:user) { NoFingerprint.create }
|
44
|
+
|
45
|
+
before do
|
46
|
+
user.update avatar: File.new('spec/support/avatar.png', 'rb')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "does not store a fingerprint" do
|
50
|
+
expect(user.attributes).to_not include('fingerprint')
|
51
|
+
end
|
52
|
+
end
|
41
53
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,12 +11,19 @@ RSpec.configure do |config|
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
# Mock Rails itself so Paperclip can write the attachments to a directory.
|
15
|
+
class Rails
|
16
|
+
def self.root
|
17
|
+
File.expand_path(File.dirname(__FILE__))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
14
21
|
class User
|
15
22
|
include Mongoid::Document
|
16
23
|
include Mongoid::Paperclip
|
17
24
|
|
18
25
|
has_mongoid_attached_file :avatar
|
19
|
-
|
26
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
20
27
|
end
|
21
28
|
|
22
29
|
class MultipleAttachments
|
@@ -24,8 +31,16 @@ class MultipleAttachments
|
|
24
31
|
include Mongoid::Paperclip
|
25
32
|
|
26
33
|
has_mongoid_attached_file :avatar
|
27
|
-
|
34
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
28
35
|
|
29
36
|
has_mongoid_attached_file :icon
|
30
|
-
|
37
|
+
validates_attachment_content_type :icon, content_type: /\Aimage\/.*\Z/
|
38
|
+
end
|
39
|
+
|
40
|
+
class NoFingerprint
|
41
|
+
include Mongoid::Document
|
42
|
+
include Mongoid::Paperclip
|
43
|
+
|
44
|
+
has_mongoid_attached_file :avatar, disable_fingerprint: true
|
45
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
31
46
|
end
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
8
|
-
|
8
|
+
- Joost Baaij
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: kt-paperclip
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - ">="
|
@@ -25,25 +26,19 @@ dependencies:
|
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: mongoid
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - ">="
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
- - "!="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 4.3.0
|
34
|
+
version: '0'
|
37
35
|
type: :runtime
|
38
36
|
prerelease: false
|
39
37
|
version_requirements: !ruby/object:Gem::Requirement
|
40
38
|
requirements:
|
41
39
|
- - ">="
|
42
40
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
- - "!="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 4.3.0
|
41
|
+
version: '0'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: bundler
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,7 +82,9 @@ dependencies:
|
|
87
82
|
- !ruby/object:Gem::Version
|
88
83
|
version: '0'
|
89
84
|
description: Enables you to use Paperclip with the Mongoid ODM for MongoDB.
|
90
|
-
email:
|
85
|
+
email:
|
86
|
+
- michael@vanrooijen.io
|
87
|
+
- joost@spacebabies.nl
|
91
88
|
executables: []
|
92
89
|
extensions: []
|
93
90
|
extra_rdoc_files: []
|
@@ -106,11 +103,11 @@ files:
|
|
106
103
|
- spec/mongoid-paperclip_spec.rb
|
107
104
|
- spec/spec_helper.rb
|
108
105
|
- spec/support/avatar.png
|
109
|
-
homepage: https://github.com/
|
106
|
+
homepage: https://github.com/mrrooijen/mongoid-paperclip
|
110
107
|
licenses:
|
111
108
|
- MIT
|
112
109
|
metadata: {}
|
113
|
-
post_install_message:
|
110
|
+
post_install_message:
|
114
111
|
rdoc_options: []
|
115
112
|
require_paths:
|
116
113
|
- lib
|
@@ -125,10 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
122
|
- !ruby/object:Gem::Version
|
126
123
|
version: '0'
|
127
124
|
requirements: []
|
128
|
-
|
129
|
-
|
130
|
-
signing_key:
|
125
|
+
rubygems_version: 3.2.3
|
126
|
+
signing_key:
|
131
127
|
specification_version: 4
|
132
128
|
summary: Paperclip compatibility for Mongoid ODM for MongoDB.
|
133
129
|
test_files: []
|
134
|
-
has_rdoc:
|