mongoid-paperclip 0.0.11 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2e6b90f64cb3a40aed4af8a37c154a262ca6d1a8
4
- data.tar.gz: 19a9f17694ee2867a40d1c9628d19a2723cc8c40
2
+ SHA256:
3
+ metadata.gz: 0ab6e33f7deca617d928cc8ed4d1faf9c5dd50fbeff677a27bd6cba978c8d332
4
+ data.tar.gz: ef2b218581e0bc51f271b8b3fb15d10b21521b63e8c848c07a62f344024e735b
5
5
  SHA512:
6
- metadata.gz: 3aa7502e748ceeeda74634a915c90b71d0c9d2aeffc0db78a9ef6dbc25f2c75e3b4ea9947befddc60af1264b8570076bcb5dc5cc829a505baeaf33bbd14a99b6
7
- data.tar.gz: 39f7aeb6c88b4c0877b540ac193478ea490ff41ac70a983494e778b3cc272526f79f2b1439104f86b310610346be00d92f1b339736978d67b28bb4af7364df1a
6
+ metadata.gz: e0b4c8f32487dcfc459bea442d8308f80b3d793eab6a3fb9fa25eb4e4fef68cd11a8a61bd56fde001762a54fc510f2e3a763c72c1c193030b58955d205fe0545
7
+ data.tar.gz: ce9af4d226b37e5fe657a36d9c53939ee6d9ca3473b238e6f60ab05266deff6483cee58b9da1cadff142c8e0a630149b45cf9b5713b7a034f871dc5626d89ede
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ mongoid-paperclip-*.gem
3
3
  .*swp
4
4
  .*swo
5
5
  .ruby-version
6
+ /spec/public
data/Gemfile.lock CHANGED
@@ -1,67 +1,64 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-paperclip (0.0.11)
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.2.6)
12
- activesupport (= 4.2.6)
13
- builder (~> 3.1)
14
- activesupport (4.2.6)
15
- i18n (~> 0.7)
16
- json (~> 1.7, >= 1.7.7)
17
- minitest (~> 5.1)
18
- thread_safe (~> 0.3, >= 0.3.4)
19
- tzinfo (~> 1.1)
20
- bson (4.1.1)
21
- builder (3.2.2)
22
- climate_control (0.0.3)
23
- activesupport (>= 3.0)
24
- cocaine (0.5.8)
25
- climate_control (>= 0.0.3, < 1.0)
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
- cocaine (~> 0.5.5)
28
+ marcel (~> 1.0.1)
46
29
  mime-types
47
- mimemagic (~> 0.3.0)
48
- rake (11.2.2)
49
- rspec (3.5.0)
50
- rspec-core (~> 3.5.0)
51
- rspec-expectations (~> 3.5.0)
52
- rspec-mocks (~> 3.5.0)
53
- rspec-core (3.5.2)
54
- rspec-support (~> 3.5.0)
55
- rspec-expectations (3.5.0)
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.5.0)
58
- rspec-mocks (3.5.0)
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.5.0)
61
- rspec-support (3.5.0)
62
- thread_safe (0.3.5)
63
- tzinfo (1.2.2)
64
- thread_safe (~> 0.1)
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
- 1.12.5
73
+ 2.2.31
data/README.md CHANGED
@@ -1,18 +1,16 @@
1
1
  # Mongoid::Paperclip
2
2
 
3
- Integrate [Paperclip](https://github.com/thoughtbot/paperclip) into [Mongoid](http://mongoid.org/).
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. This example assumes you are using **Ruby on Rails 3** and **Bundler**. However it doesn't require either.
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
- Simply define the `mongoid-paperclip` gem inside your `Gemfile`. Additionally, you can define the `aws-sdk` gem if you want to upload your files to Amazon S3. *You do not need to explicitly define the `paperclip` gem itself, since this is handled by `mongoid-paperclip`.*
10
-
11
- **Rails.root/Gemfile - Just define the following:**
10
+ **Gemfile**
12
11
 
13
12
  ```rb
14
- gem "mongoid-paperclip", :require => "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 the `has_mongoid_attached_file` method will automatically define the necessary `:avatar` fields for you in the background.
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 [Paperclip](https://github.com/thoughtbot/paperclip) I suggest checking our their official documentation and website.
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
 
@@ -1,16 +1,16 @@
1
- # encoding: utf-8
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.to_s.scan(/.{4}/).join("/")
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
  ##
@@ -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.11'
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/meskyanichi/mongoid-paperclip'
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 = %x[git ls-files].split("\n")
16
- gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
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
- validates_attachment_file_name :avatar, matches: [/image/]
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
- validates_attachment_file_name :avatar, matches: [/image/]
34
+ validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
28
35
 
29
36
  has_mongoid_attached_file :icon
30
- validates_attachment_file_name :avatar, matches: [/image/]
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.11
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
8
- autorequire:
8
+ - Joost Baaij
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-08-10 00:00:00.000000000 Z
12
+ date: 2022-01-07 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: mongoid
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: paperclip
29
+ name: mongoid
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: 2.3.6
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: 2.3.6
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: michael@vanrooijen.io
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/meskyanichi/mongoid-paperclip
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
- rubyforge_project:
129
- rubygems_version: 2.5.1
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: