mongoid-paperclip 0.0.8 → 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 +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +73 -0
- data/README.md +81 -68
- data/Rakefile +4 -0
- data/lib/mongoid-paperclip.rb +1 -0
- data/lib/mongoid_paperclip.rb +45 -10
- data/mongoid-paperclip.gemspec +14 -13
- data/spec/config/mongoid.yml +6 -0
- data/spec/mongoid-paperclip_spec.rb +53 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/avatar.png +0 -0
- metadata +90 -29
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0ab6e33f7deca617d928cc8ed4d1faf9c5dd50fbeff677a27bd6cba978c8d332
|
|
4
|
+
data.tar.gz: ef2b218581e0bc51f271b8b3fb15d10b21521b63e8c848c07a62f344024e735b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e0b4c8f32487dcfc459bea442d8308f80b3d793eab6a3fb9fa25eb4e4fef68cd11a8a61bd56fde001762a54fc510f2e3a763c72c1c193030b58955d205fe0545
|
|
7
|
+
data.tar.gz: ce9af4d226b37e5fe657a36d9c53939ee6d9ca3473b238e6f60ab05266deff6483cee58b9da1cadff142c8e0a630149b45cf9b5713b7a034f871dc5626d89ede
|
data/.gitignore
CHANGED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
mongoid-paperclip (0.1.0)
|
|
5
|
+
kt-paperclip
|
|
6
|
+
mongoid
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
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)
|
|
26
|
+
activemodel (>= 4.2.0)
|
|
27
|
+
activesupport (>= 4.2.0)
|
|
28
|
+
marcel (~> 1.0.1)
|
|
29
|
+
mime-types
|
|
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)
|
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
51
|
+
rspec-support (~> 3.10.0)
|
|
52
|
+
rspec-mocks (3.10.2)
|
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
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)
|
|
62
|
+
|
|
63
|
+
PLATFORMS
|
|
64
|
+
ruby
|
|
65
|
+
|
|
66
|
+
DEPENDENCIES
|
|
67
|
+
bundler
|
|
68
|
+
mongoid-paperclip!
|
|
69
|
+
rake
|
|
70
|
+
rspec
|
|
71
|
+
|
|
72
|
+
BUNDLED WITH
|
|
73
|
+
2.2.31
|
data/README.md
CHANGED
|
@@ -1,74 +1,71 @@
|
|
|
1
|
-
Mongoid::Paperclip
|
|
2
|
-
================================================================
|
|
1
|
+
# Mongoid::Paperclip
|
|
3
2
|
|
|
4
|
-
|
|
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)
|
|
5
5
|
|
|
6
6
|
This is actually easier and faster to set up than when using Paperclip and the ActiveRecord ORM.
|
|
7
|
-
This example assumes you are using **Ruby on Rails 3** and **Bundler**. However it doesn't require either.
|
|
8
7
|
|
|
8
|
+
## Setting it up
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
-------------
|
|
10
|
+
**Gemfile**
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
gem "mongoid-paperclip", :require => "mongoid_paperclip"
|
|
18
|
-
gem "aws-s3", :require => "aws/s3"
|
|
12
|
+
```rb
|
|
13
|
+
gem "mongoid-paperclip"
|
|
14
|
+
```
|
|
19
15
|
|
|
20
16
|
Next let's assume we have a User model and we want to allow our users to upload an avatar.
|
|
21
17
|
|
|
22
18
|
**Rails.root/app/models/user.rb - include the Mongoid::Paperclip module and invoke the provided class method**
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
has_mongoid_attached_file :avatar
|
|
29
|
-
end
|
|
20
|
+
```rb
|
|
21
|
+
class User
|
|
22
|
+
include Mongoid::Document
|
|
23
|
+
include Mongoid::Paperclip
|
|
30
24
|
|
|
25
|
+
has_mongoid_attached_file :avatar
|
|
26
|
+
end
|
|
27
|
+
```
|
|
31
28
|
|
|
32
|
-
That's it
|
|
33
|
-
--------
|
|
29
|
+
## That's it
|
|
34
30
|
|
|
35
|
-
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.
|
|
36
32
|
|
|
37
33
|
|
|
38
|
-
A more complex example
|
|
39
|
-
----------------------
|
|
34
|
+
## A more complex example
|
|
40
35
|
|
|
41
36
|
Just like Paperclip, Mongoid::Paperclip takes a second argument (hash of options) for the `has_mongoid_attached_file` method, so you can do more complex things such as in the following example.
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
```rb
|
|
39
|
+
class User
|
|
40
|
+
include Mongoid::Document
|
|
41
|
+
embeds_many :pictures
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class Picture
|
|
45
|
+
include Mongoid::Document
|
|
46
|
+
include Mongoid::Paperclip
|
|
47
|
+
|
|
48
|
+
embedded_in :user, :inverse_of => :pictures
|
|
49
|
+
|
|
50
|
+
has_mongoid_attached_file :attachment,
|
|
51
|
+
:path => ':attachment/:id/:style.:extension',
|
|
52
|
+
:storage => :s3,
|
|
53
|
+
:url => ':s3_alias_url',
|
|
54
|
+
:s3_host_alias => 'something.cloudfront.net',
|
|
55
|
+
:s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
|
|
56
|
+
:styles => {
|
|
57
|
+
:original => ['1920x1680>', :jpg],
|
|
58
|
+
:small => ['100x100#', :jpg],
|
|
59
|
+
:medium => ['250x250', :jpg],
|
|
60
|
+
:large => ['500x500>', :jpg]
|
|
61
|
+
},
|
|
62
|
+
:convert_options => { :all => '-background white -flatten +matte' }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
@user.pictures.each do |picture|
|
|
66
|
+
<%= picture.attachment.url %>
|
|
67
|
+
end
|
|
68
|
+
```
|
|
72
69
|
|
|
73
70
|
Note on embedded documents: if you plan to save or update the parent document, you MUST add cascade_callbacks: true to your
|
|
74
71
|
embeds_XXX statement. Otherwise, your data will be updated but the paperclip functions will not run to copy/update your file.
|
|
@@ -76,28 +73,44 @@ embeds_XXX statement. Otherwise, your data will be updated but the paperclip fu
|
|
|
76
73
|
In the above example:
|
|
77
74
|
|
|
78
75
|
```ruby
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
@user.update_attributes({ ... :pictures => [...] })
|
|
76
|
+
class User
|
|
77
|
+
embeds_many :pictures, :cascade_callbacks => true
|
|
78
|
+
accepts_nested_attributes_for :pictures, ...
|
|
79
|
+
attr_accepted :pictures_attributes, ...
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
@user.update_attributes({ ... :pictures => [...] })
|
|
88
83
|
```
|
|
89
84
|
|
|
85
|
+
## Optional fingerprinting
|
|
90
86
|
|
|
91
|
-
|
|
92
|
-
------------
|
|
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:
|
|
93
88
|
|
|
94
|
-
|
|
89
|
+
```rb
|
|
90
|
+
class User
|
|
91
|
+
include Mongoid::Document
|
|
92
|
+
include Mongoid::Paperclip
|
|
95
93
|
|
|
96
|
-
|
|
94
|
+
has_mongoid_attached_file :usage_report, disable_fingerprint: true
|
|
95
|
+
end
|
|
96
|
+
```
|
|
97
97
|
|
|
98
|
+
## Testing
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
-------
|
|
100
|
+
If you want to help develop this plugin, clone the repo and bundle to get all dependencies.
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
Then to run the tests:
|
|
103
103
|
|
|
104
|
+
```
|
|
105
|
+
rspec
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## There you go
|
|
109
|
+
|
|
110
|
+
Quite a lot of people have been looking for a solution to use Paperclip with Mongoid so I hope this helps!
|
|
111
|
+
|
|
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.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
Mongoid::Paperclip is released under the MIT license. See LICENSE for more information.
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'mongoid_paperclip'
|
data/lib/mongoid_paperclip.rb
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
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
|
+
end
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# mongoid criteria uses a different syntax.
|
|
18
|
+
module Paperclip
|
|
19
|
+
module Helpers
|
|
20
|
+
def each_instance_with_attachment(klass, name)
|
|
21
|
+
class_for(klass).unscoped.where("#{name}_file_name".to_sym.ne => nil).each do |instance|
|
|
22
|
+
yield(instance)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
14
26
|
end
|
|
15
27
|
|
|
16
28
|
##
|
|
@@ -38,6 +50,7 @@ end
|
|
|
38
50
|
# field :avatar_content_type, :type => String
|
|
39
51
|
# field :avatar_file_size, :type => Integer
|
|
40
52
|
# field :avatar_updated_at, :type => DateTime
|
|
53
|
+
# field :avatar_fingerprint, :type => String
|
|
41
54
|
#
|
|
42
55
|
module Mongoid
|
|
43
56
|
module Paperclip
|
|
@@ -50,12 +63,33 @@ module Mongoid
|
|
|
50
63
|
|
|
51
64
|
module ClassMethods
|
|
52
65
|
|
|
66
|
+
##
|
|
67
|
+
# Adds after_commit
|
|
68
|
+
def after_commit(*args, &block)
|
|
69
|
+
options = args.pop if args.last.is_a? Hash
|
|
70
|
+
if options
|
|
71
|
+
case options[:on]
|
|
72
|
+
when :create
|
|
73
|
+
after_create(*args, &block)
|
|
74
|
+
when :update
|
|
75
|
+
after_update(*args, &block)
|
|
76
|
+
when :destroy
|
|
77
|
+
after_destroy(*args, &block)
|
|
78
|
+
else
|
|
79
|
+
after_save(*args, &block)
|
|
80
|
+
end
|
|
81
|
+
else
|
|
82
|
+
after_save(*args, &block)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
53
86
|
##
|
|
54
87
|
# Adds Mongoid::Paperclip's "#has_mongoid_attached_file" class method to the model
|
|
55
88
|
# which includes Paperclip and Paperclip::Glue in to the model. Additionally
|
|
56
89
|
# it'll also add the required fields for Paperclip since MongoDB is schemaless and doesn't
|
|
57
90
|
# have migrations.
|
|
58
91
|
def has_mongoid_attached_file(field, options = {})
|
|
92
|
+
disable_fingerprint = options.delete(:disable_fingerprint)
|
|
59
93
|
|
|
60
94
|
##
|
|
61
95
|
# Include Paperclip and Paperclip::Glue for compatibility
|
|
@@ -63,7 +97,7 @@ module Mongoid
|
|
|
63
97
|
include ::Paperclip
|
|
64
98
|
include ::Paperclip::Glue
|
|
65
99
|
end
|
|
66
|
-
|
|
100
|
+
|
|
67
101
|
##
|
|
68
102
|
# Invoke Paperclip's #has_attached_file method and passes in the
|
|
69
103
|
# arguments specified by the user that invoked Mongoid::Paperclip#has_mongoid_attached_file
|
|
@@ -75,6 +109,7 @@ module Mongoid
|
|
|
75
109
|
field(:"#{field}_content_type", :type => String)
|
|
76
110
|
field(:"#{field}_file_size", :type => Integer)
|
|
77
111
|
field(:"#{field}_updated_at", :type => DateTime)
|
|
112
|
+
field(:"#{field}_fingerprint", :type => String) unless disable_fingerprint
|
|
78
113
|
end
|
|
79
114
|
|
|
80
115
|
##
|
data/mongoid-paperclip.gemspec
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
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 = '
|
|
10
|
-
gem.homepage = 'https://github.com/
|
|
11
|
-
gem.summary = '
|
|
12
|
-
gem.description = '
|
|
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'
|
|
8
|
+
gem.summary = 'Paperclip compatibility for Mongoid ODM for MongoDB.'
|
|
9
|
+
gem.description = 'Enables you to use Paperclip with the Mongoid ODM for MongoDB.'
|
|
10
|
+
gem.license = 'MIT'
|
|
13
11
|
|
|
14
|
-
gem.files =
|
|
15
|
-
gem.test_files =
|
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
|
13
|
+
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
|
16
14
|
gem.require_path = 'lib'
|
|
17
15
|
|
|
18
|
-
gem.add_dependency 'paperclip'
|
|
16
|
+
gem.add_dependency 'kt-paperclip'
|
|
17
|
+
gem.add_dependency 'mongoid'
|
|
19
18
|
|
|
19
|
+
gem.add_development_dependency 'bundler'
|
|
20
|
+
gem.add_development_dependency 'rake'
|
|
21
|
+
gem.add_development_dependency 'rspec'
|
|
20
22
|
end
|
|
21
|
-
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Mongoid::Paperclip, type: :unit do
|
|
4
|
+
describe "avatar" do
|
|
5
|
+
let(:user) { User.create }
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
user.update avatar: File.new('spec/support/avatar.png', 'rb')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "stores file_name" do
|
|
12
|
+
expect(user.avatar_file_name).to eq("avatar.png")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "stores content_type" do
|
|
16
|
+
expect(user.avatar_content_type).to eq("image/png")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "stores file_size" do
|
|
20
|
+
expect(user.avatar_file_size).to eq(357)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "stores updated_at" do
|
|
24
|
+
expect(user.avatar_updated_at).to be_present
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "stores fingerprint" do
|
|
28
|
+
expect(user.avatar_fingerprint).to eq("2584a801e588b3fcf4aa074efff77e30")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "multiple attachments" do
|
|
33
|
+
let(:user) { MultipleAttachments.create }
|
|
34
|
+
|
|
35
|
+
it "works" do
|
|
36
|
+
user.update avatar: File.new('spec/support/avatar.png', 'rb'), icon: File.new('spec/support/avatar.png', 'rb')
|
|
37
|
+
expect(user.avatar_file_name).to eq("avatar.png")
|
|
38
|
+
expect(user.icon_file_name).to eq("avatar.png")
|
|
39
|
+
end
|
|
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
|
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
require 'mongoid'
|
|
3
|
+
require 'mongoid-paperclip'
|
|
4
|
+
|
|
5
|
+
ENV['MONGOID_ENV'] = 'test'
|
|
6
|
+
Mongoid.load!('./spec/config/mongoid.yml')
|
|
7
|
+
|
|
8
|
+
RSpec.configure do |config|
|
|
9
|
+
config.before(:each) do
|
|
10
|
+
Mongoid.purge!
|
|
11
|
+
end
|
|
12
|
+
end
|
|
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
|
+
|
|
21
|
+
class User
|
|
22
|
+
include Mongoid::Document
|
|
23
|
+
include Mongoid::Paperclip
|
|
24
|
+
|
|
25
|
+
has_mongoid_attached_file :avatar
|
|
26
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class MultipleAttachments
|
|
30
|
+
include Mongoid::Document
|
|
31
|
+
include Mongoid::Paperclip
|
|
32
|
+
|
|
33
|
+
has_mongoid_attached_file :avatar
|
|
34
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
|
35
|
+
|
|
36
|
+
has_mongoid_attached_file :icon
|
|
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/
|
|
46
|
+
end
|
|
Binary file
|
metadata
CHANGED
|
@@ -1,68 +1,129 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid-paperclip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.1.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Michael van Rooijen
|
|
9
|
-
|
|
8
|
+
- Joost Baaij
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name: paperclip
|
|
15
|
+
name: kt-paperclip
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
17
|
requirements:
|
|
19
|
-
- -
|
|
18
|
+
- - ">="
|
|
20
19
|
- !ruby/object:Gem::Version
|
|
21
|
-
version:
|
|
20
|
+
version: '0'
|
|
22
21
|
type: :runtime
|
|
23
22
|
prerelease: false
|
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
24
|
requirements:
|
|
27
|
-
- -
|
|
25
|
+
- - ">="
|
|
28
26
|
- !ruby/object:Gem::Version
|
|
29
|
-
version:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
version: '0'
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: mongoid
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
type: :runtime
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: bundler
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
type: :development
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: rake
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: rspec
|
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
description: Enables you to use Paperclip with the Mongoid ODM for MongoDB.
|
|
85
|
+
email:
|
|
86
|
+
- michael@vanrooijen.io
|
|
87
|
+
- joost@spacebabies.nl
|
|
33
88
|
executables: []
|
|
34
89
|
extensions: []
|
|
35
90
|
extra_rdoc_files: []
|
|
36
91
|
files:
|
|
37
|
-
- .gitignore
|
|
92
|
+
- ".gitignore"
|
|
93
|
+
- ".rspec"
|
|
94
|
+
- Gemfile
|
|
95
|
+
- Gemfile.lock
|
|
38
96
|
- LICENSE
|
|
39
97
|
- README.md
|
|
98
|
+
- Rakefile
|
|
99
|
+
- lib/mongoid-paperclip.rb
|
|
40
100
|
- lib/mongoid_paperclip.rb
|
|
41
101
|
- mongoid-paperclip.gemspec
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
102
|
+
- spec/config/mongoid.yml
|
|
103
|
+
- spec/mongoid-paperclip_spec.rb
|
|
104
|
+
- spec/spec_helper.rb
|
|
105
|
+
- spec/support/avatar.png
|
|
106
|
+
homepage: https://github.com/mrrooijen/mongoid-paperclip
|
|
107
|
+
licenses:
|
|
108
|
+
- MIT
|
|
109
|
+
metadata: {}
|
|
110
|
+
post_install_message:
|
|
45
111
|
rdoc_options: []
|
|
46
112
|
require_paths:
|
|
47
113
|
- lib
|
|
48
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
|
-
none: false
|
|
50
115
|
requirements:
|
|
51
|
-
- -
|
|
116
|
+
- - ">="
|
|
52
117
|
- !ruby/object:Gem::Version
|
|
53
118
|
version: '0'
|
|
54
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
|
-
none: false
|
|
56
120
|
requirements:
|
|
57
|
-
- -
|
|
121
|
+
- - ">="
|
|
58
122
|
- !ruby/object:Gem::Version
|
|
59
123
|
version: '0'
|
|
60
124
|
requirements: []
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
summary: Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for
|
|
66
|
-
MongoDB.
|
|
125
|
+
rubygems_version: 3.2.3
|
|
126
|
+
signing_key:
|
|
127
|
+
specification_version: 4
|
|
128
|
+
summary: Paperclip compatibility for Mongoid ODM for MongoDB.
|
|
67
129
|
test_files: []
|
|
68
|
-
has_rdoc:
|