shrine-mongoid 0.1.1 → 0.2.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
2
  SHA1:
3
- metadata.gz: 457327abef8a36c4c4399a0513e83f10a01ca2d1
4
- data.tar.gz: 4b5fa6a03c7599128bc4cd60925ae3e3094f73a8
3
+ metadata.gz: cb59e93b83c5e0df8f48471ebaa914c5d97f0931
4
+ data.tar.gz: b07bbddb23270e8820c95375b8d57d171a9631a5
5
5
  SHA512:
6
- metadata.gz: 95c76c9c88508047d4f51bece1fcae5191d03d8432562f14e67954873f59a146f93b29e696362b8a89d2349215c6eb2458dac6e3ca0f2f52a57cf845f5e60b37
7
- data.tar.gz: adabc0c209e29afb6437fe63f3f780b4ecb513460120c41432d70849c30b78d11ad216c3fd11196e5df8408b615153587489effbd4b59381ed5b203034000c06
6
+ metadata.gz: 5dfc4f7494ac3bf223cc29b2c1cdaf17e853b4cc494f079ec655b8158b54a71ee6939894028fd2a7bb1edfd0c8e2b405b594eaaa3cf755b71fe64e0ef46ef1b7
7
+ data.tar.gz: efe40aed3f3260b02edd873a753ba003c0b18dd6f73960b2667868fbdea83a8ed170f049fe0ce672887175b0e7cffcce877e3b4b4b14fcde0e79f2017e47cda3
data/README.md CHANGED
@@ -21,6 +21,9 @@ class Post
21
21
  field :image_data, type: String
22
22
  end
23
23
  ```
24
+
25
+ This plugin will add validations and callbacks:
26
+
24
27
  ```rb
25
28
  post = Post.new
26
29
  post.image = file
@@ -31,6 +34,13 @@ post.destroy
31
34
  post.image.exists? #=> false
32
35
  ```
33
36
 
37
+ If for some reason you don't want callbacks and/or validations, you can turn
38
+ them off:
39
+
40
+ ```rb
41
+ plugin :mongoid, callbacks: false, validations: false
42
+ ```
43
+
34
44
  ## Contributing
35
45
 
36
46
  You can run the tests with the Rake task:
@@ -3,31 +3,42 @@ require "mongoid"
3
3
  class Shrine
4
4
  module Plugins
5
5
  module Mongoid
6
+ def self.configure(uploader, opts = {})
7
+ uploader.opts[:mongoid_callbacks] = opts.fetch(:callbacks, uploader.opts.fetch(:mongoid_callbacks, true))
8
+ uploader.opts[:mongoid_validations] = opts.fetch(:validations, uploader.opts.fetch(:mongoid_validations, true))
9
+ end
10
+
6
11
  module AttachmentMethods
7
12
  def included(model)
8
13
  super
9
14
 
10
15
  return unless model < ::Mongoid::Document
11
16
 
12
- model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
13
- validate do
14
- #{@name}_attacher.errors.each do |message|
15
- errors.add(:#{@name}, message)
17
+ if shrine_class.opts[:mongoid_validations]
18
+ model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
19
+ validate do
20
+ #{@name}_attacher.errors.each do |message|
21
+ errors.add(:#{@name}, message)
22
+ end
16
23
  end
17
- end
24
+ RUBY
25
+ end
18
26
 
19
- before_save do
20
- #{@name}_attacher.save if #{@name}_attacher.attached?
21
- end
27
+ if shrine_class.opts[:mongoid_callbacks]
28
+ model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
29
+ before_save do
30
+ #{@name}_attacher.save if #{@name}_attacher.attached?
31
+ end
22
32
 
23
- after_save do
24
- #{@name}_attacher.finalize if #{@name}_attacher.attached?
25
- end
33
+ after_save do
34
+ #{@name}_attacher.finalize if #{@name}_attacher.attached?
35
+ end
26
36
 
27
- after_destroy do
28
- #{@name}_attacher.destroy
29
- end
30
- RUBY
37
+ after_destroy do
38
+ #{@name}_attacher.destroy
39
+ end
40
+ RUBY
41
+ end
31
42
  end
32
43
  end
33
44
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "shrine-mongoid"
3
- gem.version = "0.1.1"
3
+ gem.version = "0.2.0"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shrine
@@ -130,4 +130,3 @@ signing_key:
130
130
  specification_version: 4
131
131
  summary: Provides Mongoid integration for Shrine.
132
132
  test_files: []
133
- has_rdoc: