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 +4 -4
- data/README.md +10 -0
- data/lib/shrine/plugins/mongoid.rb +26 -15
- data/shrine-mongoid.gemspec +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb59e93b83c5e0df8f48471ebaa914c5d97f0931
|
4
|
+
data.tar.gz: b07bbddb23270e8820c95375b8d57d171a9631a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
24
|
+
RUBY
|
25
|
+
end
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
33
|
+
after_save do
|
34
|
+
#{@name}_attacher.finalize if #{@name}_attacher.attached?
|
35
|
+
end
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
after_destroy do
|
38
|
+
#{@name}_attacher.destroy
|
39
|
+
end
|
40
|
+
RUBY
|
41
|
+
end
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
data/shrine-mongoid.gemspec
CHANGED
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.
|
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-
|
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:
|