shrine-mongoid 0.1.0

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: c753389b0e8dbac16ab9540cf4af2071256cb02c
4
+ data.tar.gz: afe9e3cfadcc2bc5cfac83b7ad15c1a49c40f7a3
5
+ SHA512:
6
+ metadata.gz: 2e0af6da233ca982da982df77ee0215755b24a3c472b0ee8d1879cb442de038e8d6cb3d1223cfc57f3b21b18af337a4c5027b27faff424af08562bf4f7172378
7
+ data.tar.gz: 09f7a5f893d27752ff5c36e4e29e5ca1e5a838da36056a06d26ae9ffc0dfd63067b5431afb4bc9a765b3a699c218fb6179bb15ca70b8d0b5c19c4cebcbcc1231
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Janko Marohnić
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Shrine::Mongoid
2
+
3
+ Provides [Mongoid] integration for [Shrine].
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem "shrine-mongoid"
9
+ gem "shrine", github: "janko-m/shrine" # backgrounding support
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```rb
15
+ Shrine.plugin :mongoid
16
+ ```
17
+ ```rb
18
+ class Post
19
+ include Mongoid::Document
20
+ include ImageUploader[:image]
21
+
22
+ field :image_data, type: String
23
+ end
24
+ ```
25
+ ```rb
26
+ post = Post.new
27
+ post.image = file
28
+ post.image.storage_key #=> "cache"
29
+ post.save
30
+ post.image.storage_key #=> "store"
31
+ post.destroy
32
+ post.image.exists? #=> false
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ You can run the tests with the Rake task:
38
+
39
+ ```
40
+ $ bundle exec rake test
41
+ ```
42
+
43
+ ## License
44
+
45
+ [MIT](LICENSE.txt)
46
+
47
+ [Mongoid]: https://github.com/mongodb/mongoid
48
+ [Shrine]: https://github.com/janko-m/shrine
@@ -0,0 +1,62 @@
1
+ require "mongoid"
2
+
3
+ class Shrine
4
+ module Plugins
5
+ module Mongoid
6
+ module AttachmentMethods
7
+ def included(model)
8
+ super
9
+
10
+ return unless model < ::Mongoid::Document
11
+
12
+ model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
13
+ validate do
14
+ #{@name}_attacher.errors.each do |message|
15
+ errors.add(:#{@name}, message)
16
+ end
17
+ end
18
+
19
+ before_save do
20
+ #{@name}_attacher.save if #{@name}_attacher.attached?
21
+ end
22
+
23
+ after_save do
24
+ #{@name}_attacher.finalize if #{@name}_attacher.attached?
25
+ end
26
+
27
+ after_destroy do
28
+ #{@name}_attacher.destroy
29
+ end
30
+ RUBY
31
+ end
32
+ end
33
+
34
+ module AttacherClassMethods
35
+ # Needed by the backgrounding plugin.
36
+ def find_record(record_class, record_id)
37
+ record_class.where(id: record_id).first
38
+ end
39
+ end
40
+
41
+ module AttacherMethods
42
+ private
43
+
44
+ # Updates the current attachment with the new one, unless the current
45
+ # attachment has changed.
46
+ def swap(uploaded_file)
47
+ return if record.send(:"#{name}_data") != record.reload.send(:"#{name}_data")
48
+ super
49
+ rescue ::Mongoid::Errors::DocumentNotFound
50
+ end
51
+
52
+ # We save the record after updating, raising any validation errors.
53
+ def update(uploaded_file)
54
+ super
55
+ record.save!
56
+ end
57
+ end
58
+ end
59
+
60
+ register_plugin(:mongoid, Mongoid)
61
+ end
62
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "shrine-mongoid"
3
+ gem.version = "0.1.0"
4
+
5
+ gem.required_ruby_version = ">= 2.1"
6
+
7
+ gem.summary = "Provides Mongoid integration for Shrine."
8
+ gem.homepage = "https://github.com/janko-m/shrine-mongoid"
9
+ gem.authors = ["Janko Marohnić"]
10
+ gem.email = ["janko.marohnic@gmail.com"]
11
+ gem.license = "MIT"
12
+
13
+ gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "*.gemspec"]
14
+ gem.require_path = "lib"
15
+
16
+ gem.add_dependency "shrine"
17
+ gem.add_dependency "mongoid", "~> 5.0"
18
+
19
+ gem.add_development_dependency "shrine-memory"
20
+ gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "minitest"
22
+ gem.add_development_dependency "mocha"
23
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shrine-mongoid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Janko Marohnić
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shrine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongoid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: shrine-memory
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - janko.marohnic@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ - lib/shrine/plugins/mongoid.rb
107
+ - shrine-mongoid.gemspec
108
+ homepage: https://github.com/janko-m/shrine-mongoid
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '2.1'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.5.1
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Provides Mongoid integration for Shrine.
132
+ test_files: []
133
+ has_rdoc: