mongoid-paperclip 0.0.10 → 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: 6b71a10cb6e4bda939a9ee5692fb27fa70c28d66
4
- data.tar.gz: 1edfa298dd290a24bd777a9fc4b5b62bc64c6649
2
+ SHA256:
3
+ metadata.gz: 0ab6e33f7deca617d928cc8ed4d1faf9c5dd50fbeff677a27bd6cba978c8d332
4
+ data.tar.gz: ef2b218581e0bc51f271b8b3fb15d10b21521b63e8c848c07a62f344024e735b
5
5
  SHA512:
6
- metadata.gz: b8f886a33c01fda2d8d3441a48a32139f40334749ba748a07b035568c3e861125865ebc4f7ea8af0b8764a11115ec417bb8b874e19dd9260c2b40c2046dae21f
7
- data.tar.gz: b4e93cf51352a7bee4f59a695ebaa9680d64e4d870ef6680cd2a20648dd9d58436c43972cabadf5f5fb44e076c3f96b3045e2ab5aec375b2c7c961540e1a5a47
6
+ metadata.gz: e0b4c8f32487dcfc459bea442d8308f80b3d793eab6a3fb9fa25eb4e4fef68cd11a8a61bd56fde001762a54fc510f2e3a763c72c1c193030b58955d205fe0545
7
+ data.tar.gz: ce9af4d226b37e5fe657a36d9c53939ee6d9ca3473b238e6f60ab05266deff6483cee58b9da1cadff142c8e0a630149b45cf9b5713b7a034f871dc5626d89ede
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  mongoid-paperclip-*.gem
3
3
  .*swp
4
4
  .*swo
5
+ .ruby-version
6
+ /spec/public
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Use the gemspec for all dependencies.
4
+ gemspec
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,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,11 +82,34 @@ 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
+
98
+ ## Testing
99
+
100
+ If you want to help develop this plugin, clone the repo and bundle to get all dependencies.
101
+
102
+ Then to run the tests:
103
+
104
+ ```
105
+ rspec
106
+ ```
107
+
87
108
  ## There you go
88
109
 
89
110
  Quite a lot of people have been looking for a solution to use Paperclip with Mongoid so I hope this helps!
90
111
 
91
- 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.
92
113
 
93
114
  ## License
94
115
 
@@ -0,0 +1 @@
1
+ require 'mongoid_paperclip'
@@ -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
  ##
@@ -62,7 +62,7 @@ module Mongoid
62
62
  end
63
63
 
64
64
  module ClassMethods
65
-
65
+
66
66
  ##
67
67
  # Adds after_commit
68
68
  def after_commit(*args, &block)
@@ -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,20 +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.10'
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
 
19
- gem.add_dependency 'paperclip', ['>= 2.3.6', '!=4.3.0']
16
+ gem.add_dependency 'kt-paperclip'
17
+ gem.add_dependency 'mongoid'
18
+
19
+ gem.add_development_dependency 'bundler'
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec'
20
22
  end
@@ -0,0 +1,6 @@
1
+ test:
2
+ clients:
3
+ default:
4
+ database: mongoid-paperclip
5
+ hosts:
6
+ - localhost:27017
@@ -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
@@ -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,52 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
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: 2015-08-21 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: paperclip
15
+ name: kt-paperclip
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: 2.3.6
20
- - - "!="
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: mongoid
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
21
33
  - !ruby/object:Gem::Version
22
- version: 4.3.0
34
+ version: '0'
23
35
  type: :runtime
24
36
  prerelease: false
25
37
  version_requirements: !ruby/object:Gem::Requirement
26
38
  requirements:
27
39
  - - ">="
28
40
  - !ruby/object:Gem::Version
29
- version: 2.3.6
30
- - - "!="
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
+ - - ">="
31
82
  - !ruby/object:Gem::Version
32
- version: 4.3.0
83
+ version: '0'
33
84
  description: Enables you to use Paperclip with the Mongoid ODM for MongoDB.
34
- email: michael@vanrooijen.io
85
+ email:
86
+ - michael@vanrooijen.io
87
+ - joost@spacebabies.nl
35
88
  executables: []
36
89
  extensions: []
37
90
  extra_rdoc_files: []
38
91
  files:
39
92
  - ".gitignore"
93
+ - ".rspec"
94
+ - Gemfile
95
+ - Gemfile.lock
40
96
  - LICENSE
41
97
  - README.md
42
98
  - Rakefile
99
+ - lib/mongoid-paperclip.rb
43
100
  - lib/mongoid_paperclip.rb
44
101
  - mongoid-paperclip.gemspec
45
- homepage: https://github.com/meskyanichi/mongoid-paperclip
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
46
107
  licenses:
47
108
  - MIT
48
109
  metadata: {}
49
- post_install_message:
110
+ post_install_message:
50
111
  rdoc_options: []
51
112
  require_paths:
52
113
  - lib
@@ -61,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
122
  - !ruby/object:Gem::Version
62
123
  version: '0'
63
124
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.4.5
66
- signing_key:
125
+ rubygems_version: 3.2.3
126
+ signing_key:
67
127
  specification_version: 4
68
128
  summary: Paperclip compatibility for Mongoid ODM for MongoDB.
69
129
  test_files: []