refile-sequel 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1df3ca07e141c8565d58a557cadda890a654286
4
+ data.tar.gz: 613dfd8e6ece772f0f6a2c6c8aa4ab0ce13e951a
5
+ SHA512:
6
+ metadata.gz: bd5ee7059986f169602e0b45877869731bc5473569656555807bbf4f2b2d291787fd248e402310a1ae9c7964d446e5554670770ad257d54f9141ed47a04c431d
7
+ data.tar.gz: dc6fb22795f1eeceb05f388690aee77556e304c3509d51330d8780f6dd0d5afe84af7e8c41a31c79847f10012edc70d9fe70bb157a1f7350e21fff65f47cf25f
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 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.
@@ -0,0 +1,27 @@
1
+ # Refile::Sequel
2
+
3
+ [Sequel](http://sequel.jeremyevans.net/) extension for [Refile](https://github.com/refile/refile).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'refile-sequel'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ require "refile/sequel"
17
+
18
+ Sequel::Model.extend Refile::Sequel::Attachment
19
+
20
+ class User < Sequel::Model
21
+ attachment :profile_image
22
+ end
23
+ ```
24
+
25
+ ## License
26
+
27
+ [MIT](/LICENSE.txt)
@@ -0,0 +1 @@
1
+ require "refile/sequel/attachment"
@@ -0,0 +1,46 @@
1
+ require "refile"
2
+
3
+ module Refile
4
+ module Sequel
5
+ module Attachment
6
+ include Refile::Attachment
7
+
8
+ def attachment(name, raise_errors: false, **options)
9
+ super # includes a module
10
+
11
+ attachment_module = ancestors[1]
12
+ attacher = "#{name}_attacher"
13
+
14
+ attachment_module.class_eval do
15
+ define_method(:validate) do
16
+ super()
17
+ if send(attacher).present?
18
+ send(attacher).valid?
19
+ send(attacher).errors.each do |error|
20
+ errors.add(name, error)
21
+ end
22
+ end
23
+ end
24
+
25
+ define_method(:before_save) do
26
+ super()
27
+ send(attacher).store!
28
+ end
29
+
30
+ define_method(:after_destroy) do
31
+ super()
32
+ send(attacher).delete!
33
+ end
34
+
35
+ # Sequel::Model#update internally calls #save_changes, which saves
36
+ # the record only if columns have changed. So, if you were to do
37
+ # `User[23].update(avatar: new_image)`, the attachment wouldn't get
38
+ # updated, because changing of "avatar_id" column happens only in
39
+ # `before_save`, which doesn't get triggered. This forces each record
40
+ # to always save itself, thus triggering all hooks.
41
+ define_method(:save_changes) { save }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refile-sequel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Janko Marohnić
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: refile
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sequel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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: sqlite3
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: Sequel ORM integration of the Refile gem
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/refile/sequel.rb
107
+ - lib/refile/sequel/attachment.rb
108
+ homepage: https://github.com/janko-m/refile-sequel
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.0
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.4.5
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Sequel ORM integration of the Refile gem
132
+ test_files: []