8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/refile/sequel/attachment.rb', line 8
def attachment(name, raise_errors: false, **options)
super
attachment_module = ancestors[1]
attacher = "#{name}_attacher"
attachment_module.class_eval do
define_method(:validate) do
super()
if send(attacher).present?
send(attacher).valid?
send(attacher).errors.each do |error|
errors.add(name, error)
end
end
end
define_method(:before_save) do
super()
send(attacher).store!
end
define_method(:after_destroy) do
super()
send(attacher).delete!
end
define_method(:save_changes) { save }
end
end
|