mongoid-paperclip 0.0.8 → 0.0.9

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: 35e6405440ac699b2855f43de9b4a9e3208a2d89
4
+ data.tar.gz: 4f41a41a63eb82afebee3d081460677e12980f56
5
+ SHA512:
6
+ metadata.gz: d76b2d4b8e890cb0b78d254e71b19699de126eca6af8f9eecc326908d7e96055851ed03fc90b2129d2fb4023a67792c1aa204d1ad27ee461617e033815bcc37a
7
+ data.tar.gz: 6afa66529d395440eb6b949c9080cc00f5ecc6e3f4cc1baac3d9b2b4fbdcf74eadc8c38593418162f4ed5cd999750e8db3448e5ac97d4dc9e7d65f52e921bfa6
data/README.md CHANGED
@@ -1,74 +1,73 @@
1
- Mongoid::Paperclip - Making Paperclip play nice with Mongoid ODM
2
- ================================================================
1
+ # Mongoid::Paperclip
3
2
 
4
- As the title suggests: `Mongoid::Paperclip` makes it easy to hook up [Paperclip](https://github.com/thoughtbot/paperclip) with [Mongoid](http://mongoid.org/).
3
+ Integrate [Paperclip](https://github.com/thoughtbot/paperclip) into [Mongoid](http://mongoid.org/).
5
4
 
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.
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.
8
6
 
7
+ ## Setting it up
9
8
 
10
- Setting it up
11
- -------------
12
-
13
- Simply define the `mongoid-paperclip` gem inside your `Gemfile`. Additionally, you can define the `aws-s3` 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`.*
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`.*
14
10
 
15
11
  **Rails.root/Gemfile - Just define the following:**
16
12
 
17
- gem "mongoid-paperclip", :require => "mongoid_paperclip"
18
- gem "aws-s3", :require => "aws/s3"
13
+ ```rb
14
+ gem "mongoid-paperclip", :require => "mongoid_paperclip"
15
+ gem 'aws-sdk', '~> 1.3.4'
16
+ ```
19
17
 
20
18
  Next let's assume we have a User model and we want to allow our users to upload an avatar.
21
19
 
22
20
  **Rails.root/app/models/user.rb - include the Mongoid::Paperclip module and invoke the provided class method**
23
21
 
24
- class User
25
- include Mongoid::Document
26
- include Mongoid::Paperclip
27
-
28
- has_mongoid_attached_file :avatar
29
- end
22
+ ```rb
23
+ class User
24
+ include Mongoid::Document
25
+ include Mongoid::Paperclip
30
26
 
27
+ has_mongoid_attached_file :avatar
28
+ end
29
+ ```
31
30
 
32
- That's it
33
- --------
31
+ ## That's it
34
32
 
35
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.
36
34
 
37
35
 
38
- A more complex example
39
- ----------------------
36
+ ## A more complex example
40
37
 
41
38
  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
39
 
43
- class User
44
- include Mongoid::Document
45
- embeds_many :pictures
46
- end
47
-
48
- class Picture
49
- include Mongoid::Document
50
- include Mongoid::Paperclip
51
-
52
- embedded_in :user, :inverse_of => :pictures
53
-
54
- has_mongoid_attached_file :attachment,
55
- :path => ':attachment/:id/:style.:extension',
56
- :storage => :s3,
57
- :url => ':s3_alias_url',
58
- :s3_host_alias => 'something.cloudfront.net',
59
- :s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
60
- :styles => {
61
- :original => ['1920x1680>', :jpg],
62
- :small => ['100x100#', :jpg],
63
- :medium => ['250x250', :jpg],
64
- :large => ['500x500>', :jpg]
65
- },
66
- :convert_options => { :all => '-background white -flatten +matte' }
67
- end
68
-
69
- @user.pictures.each do |picture|
70
- <%= picture.attachment.url %>
71
- end
40
+ ```rb
41
+ class User
42
+ include Mongoid::Document
43
+ embeds_many :pictures
44
+ end
45
+
46
+ class Picture
47
+ include Mongoid::Document
48
+ include Mongoid::Paperclip
49
+
50
+ embedded_in :user, :inverse_of => :pictures
51
+
52
+ has_mongoid_attached_file :attachment,
53
+ :path => ':attachment/:id/:style.:extension',
54
+ :storage => :s3,
55
+ :url => ':s3_alias_url',
56
+ :s3_host_alias => 'something.cloudfront.net',
57
+ :s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
58
+ :styles => {
59
+ :original => ['1920x1680>', :jpg],
60
+ :small => ['100x100#', :jpg],
61
+ :medium => ['250x250', :jpg],
62
+ :large => ['500x500>', :jpg]
63
+ },
64
+ :convert_options => { :all => '-background white -flatten +matte' }
65
+ end
66
+
67
+ @user.pictures.each do |picture|
68
+ <%= picture.attachment.url %>
69
+ end
70
+ ```
72
71
 
73
72
  Note on embedded documents: if you plan to save or update the parent document, you MUST add cascade_callbacks: true to your
74
73
  embeds_XXX statement. Otherwise, your data will be updated but the paperclip functions will not run to copy/update your file.
@@ -76,28 +75,21 @@ embeds_XXX statement. Otherwise, your data will be updated but the paperclip fu
76
75
  In the above example:
77
76
 
78
77
  ```ruby
79
- class User
80
- ...
81
- embeds_many :pictures, :cascade_callbacks => true
82
- accepts_nested_attributes_for :pictures, ...
83
- attr_accepted :pictures_attributes, ...
84
- ...
85
- end
86
-
87
- @user.update_attributes({ ... :pictures => [...] })
88
- ```
78
+ class User
79
+ embeds_many :pictures, :cascade_callbacks => true
80
+ accepts_nested_attributes_for :pictures, ...
81
+ attr_accepted :pictures_attributes, ...
82
+ end
89
83
 
84
+ @user.update_attributes({ ... :pictures => [...] })
85
+ ```
90
86
 
91
- There you go
92
- ------------
87
+ ## There you go
93
88
 
94
89
  Quite a lot of people have been looking for a solution to use Paperclip with Mongoid so I hope this helps!
95
90
 
96
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.
97
92
 
98
-
99
- License
100
- -------
93
+ ## License
101
94
 
102
95
  Mongoid::Paperclip is released under the MIT license. See LICENSE for more information.
103
-
@@ -13,6 +13,18 @@ Paperclip.interpolates :id_partition do |attachment, style|
13
13
  attachment.instance.id.to_s.scan(/.{4}/).join("/")
14
14
  end
15
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
26
+ end
27
+
16
28
  ##
17
29
  # The Mongoid::Paperclip extension
18
30
  # Makes Paperclip play nice with the Mongoid ODM
@@ -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
@@ -49,6 +62,26 @@ module Mongoid
49
62
  end
50
63
 
51
64
  module ClassMethods
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
52
85
 
53
86
  ##
54
87
  # Adds Mongoid::Paperclip's "#has_mongoid_attached_file" class method to the model
@@ -63,7 +96,7 @@ module Mongoid
63
96
  include ::Paperclip
64
97
  include ::Paperclip::Glue
65
98
  end
66
-
99
+
67
100
  ##
68
101
  # Invoke Paperclip's #has_attached_file method and passes in the
69
102
  # arguments specified by the user that invoked Mongoid::Paperclip#has_mongoid_attached_file
@@ -75,6 +108,7 @@ module Mongoid
75
108
  field(:"#{field}_content_type", :type => String)
76
109
  field(:"#{field}_file_size", :type => Integer)
77
110
  field(:"#{field}_updated_at", :type => DateTime)
111
+ field(:"#{field}_fingerprint", :type => String)
78
112
  end
79
113
 
80
114
  ##
@@ -3,19 +3,18 @@
3
3
  Gem::Specification.new do |gem|
4
4
 
5
5
  gem.name = 'mongoid-paperclip'
6
- gem.version = '0.0.8'
6
+ gem.version = '0.0.9'
7
7
  gem.platform = Gem::Platform::RUBY
8
8
  gem.authors = 'Michael van Rooijen'
9
- gem.email = 'meskyanichi@gmail.com'
9
+ gem.email = 'michael@vanrooijen.io'
10
10
  gem.homepage = 'https://github.com/meskyanichi/mongoid-paperclip'
11
- gem.summary = 'Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for MongoDB.'
12
- gem.description = 'Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for MongoDB.'
11
+ gem.summary = 'Paperclip compatibility for Mongoid ODM for MongoDB.'
12
+ gem.description = 'Enables you to use Paperclip with the Mongoid ODM for MongoDB.'
13
+ gem.license = 'MIT'
13
14
 
14
15
  gem.files = %x[git ls-files].split("\n")
15
16
  gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
16
17
  gem.require_path = 'lib'
17
18
 
18
19
  gem.add_dependency 'paperclip', ['>= 2.3.6']
19
-
20
20
  end
21
-
metadata CHANGED
@@ -1,68 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
5
- prerelease:
4
+ version: 0.0.9
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael van Rooijen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-06 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: paperclip
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.3.6
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.3.6
30
- description: Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM
31
- for MongoDB.
32
- email: meskyanichi@gmail.com
27
+ description: Enables you to use Paperclip with the Mongoid ODM for MongoDB.
28
+ email: michael@vanrooijen.io
33
29
  executables: []
34
30
  extensions: []
35
31
  extra_rdoc_files: []
36
32
  files:
37
- - .gitignore
33
+ - ".gitignore"
38
34
  - LICENSE
39
35
  - README.md
40
36
  - lib/mongoid_paperclip.rb
41
37
  - mongoid-paperclip.gemspec
42
38
  homepage: https://github.com/meskyanichi/mongoid-paperclip
43
- licenses: []
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
44
42
  post_install_message:
45
43
  rdoc_options: []
46
44
  require_paths:
47
45
  - lib
48
46
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
47
  requirements:
51
- - - ! '>='
48
+ - - ">="
52
49
  - !ruby/object:Gem::Version
53
50
  version: '0'
54
51
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
52
  requirements:
57
- - - ! '>='
53
+ - - ">="
58
54
  - !ruby/object:Gem::Version
59
55
  version: '0'
60
56
  requirements: []
61
57
  rubyforge_project:
62
- rubygems_version: 1.8.24
58
+ rubygems_version: 2.2.2
63
59
  signing_key:
64
- specification_version: 3
65
- summary: Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for
66
- MongoDB.
60
+ specification_version: 4
61
+ summary: Paperclip compatibility for Mongoid ODM for MongoDB.
67
62
  test_files: []
68
63
  has_rdoc: