saviour 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/saviour/integrator.rb +10 -9
- data/lib/saviour/version.rb +1 -1
- data/spec/models/model_spec.rb +49 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0747dcd299b6f0a1965c583f5f8b71a3c181355f7c98a36e180e5607172af79
|
4
|
+
data.tar.gz: 1aac6b08756d18cd88869e7fa3b25b798a4bc0d543d9ebabe57436ce4edb3f0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca9ce86fa1f80542876bb174b4d74775e66849df6f067a4515fe0634d9936f69ac98b99bcf72a1c29181612a68a322241bf2d2b7f85ddc49f4af97984a0cf7a5
|
7
|
+
data.tar.gz: 2c9c98ae090b2fe969cd4e806cddfad8b86d53738d5096e87d6dd15d75f591148533fb117b6186bfb4a364443d7e774117157676644b9ac194d09a9c07f6413c
|
data/lib/saviour/integrator.rb
CHANGED
@@ -13,11 +13,11 @@ module Saviour
|
|
13
13
|
@klass.class_attribute :followers_per_leader_config
|
14
14
|
@klass.followers_per_leader_config = {}
|
15
15
|
|
16
|
-
klass = @klass
|
17
16
|
persistence_klass = @persistence_klass
|
18
17
|
|
19
18
|
@klass.define_singleton_method "attach_file" do |attach_as, *maybe_uploader_klass, **opts, &block|
|
20
|
-
|
19
|
+
self.attached_files += [attach_as]
|
20
|
+
|
21
21
|
uploader_klass = maybe_uploader_klass[0]
|
22
22
|
|
23
23
|
if opts[:follow]
|
@@ -27,8 +27,9 @@ module Saviour
|
|
27
27
|
raise(ConfigurationError, "You must specify a :dependent option when using :follow. Use either :destroy or :ignore")
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
self.followers_per_leader_config = self.followers_per_leader_config.dup
|
31
|
+
self.followers_per_leader_config[opts[:follow]] ||= []
|
32
|
+
self.followers_per_leader_config[opts[:follow]].push({ attachment: attach_as, dependent: dependent })
|
32
33
|
end
|
33
34
|
|
34
35
|
if uploader_klass.nil? && block.nil?
|
@@ -91,7 +92,7 @@ module Saviour
|
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
94
|
-
|
95
|
+
self.include mod
|
95
96
|
end
|
96
97
|
|
97
98
|
@klass.define_singleton_method("attached_followers_per_leader") do
|
@@ -103,13 +104,13 @@ module Saviour
|
|
103
104
|
@klass.class_attribute :__saviour_validations
|
104
105
|
|
105
106
|
@klass.define_singleton_method("attach_validation") do |attach_as, method_name = nil, &block|
|
106
|
-
|
107
|
-
|
107
|
+
self.__saviour_validations ||= Hash.new { [] }
|
108
|
+
self.__saviour_validations[attach_as] += [{ method_or_block: method_name || block, type: :memory }]
|
108
109
|
end
|
109
110
|
|
110
111
|
@klass.define_singleton_method("attach_validation_with_file") do |attach_as, method_name = nil, &block|
|
111
|
-
|
112
|
-
|
112
|
+
self.__saviour_validations ||= Hash.new { [] }
|
113
|
+
self.__saviour_validations[attach_as] += [{ method_or_block: method_name || block, type: :file }]
|
113
114
|
end
|
114
115
|
end
|
115
116
|
end
|
data/lib/saviour/version.rb
CHANGED
data/spec/models/model_spec.rb
CHANGED
@@ -30,4 +30,53 @@ describe Saviour do
|
|
30
30
|
|
31
31
|
expect(klass2.new.file).to respond_to :exists?
|
32
32
|
end
|
33
|
+
|
34
|
+
it "subclasses can have independent attachments" do
|
35
|
+
uploader = Class.new(Saviour::BaseUploader) do
|
36
|
+
store_dir { "/store/dir" }
|
37
|
+
end
|
38
|
+
|
39
|
+
klass = Class.new(Test) do
|
40
|
+
include Saviour::Model
|
41
|
+
end
|
42
|
+
expect(klass.attached_files).to eq([])
|
43
|
+
|
44
|
+
klass2 = Class.new(klass) do
|
45
|
+
attach_file :file, uploader
|
46
|
+
end
|
47
|
+
|
48
|
+
klass3 = Class.new(klass) do
|
49
|
+
attach_file :file_thumb, uploader
|
50
|
+
end
|
51
|
+
|
52
|
+
expect(klass2.attached_files).to eq([:file])
|
53
|
+
expect(klass.attached_files).to eq([])
|
54
|
+
expect(klass3.attached_files).to eq([:file_thumb])
|
55
|
+
end
|
56
|
+
|
57
|
+
it "subclasses can have independent attachments with followers" do
|
58
|
+
uploader = Class.new(Saviour::BaseUploader) do
|
59
|
+
store_dir { "/store/dir" }
|
60
|
+
end
|
61
|
+
|
62
|
+
klass = Class.new(Test) do
|
63
|
+
include Saviour::Model
|
64
|
+
end
|
65
|
+
|
66
|
+
klass2 = Class.new(klass) do
|
67
|
+
attach_file :file, uploader
|
68
|
+
attach_file :file_thumb, uploader, follow: :file, dependent: :destroy
|
69
|
+
end
|
70
|
+
|
71
|
+
klass3 = Class.new(klass) do
|
72
|
+
attach_file :file_thumb_2, uploader
|
73
|
+
attach_file :file_thumb_3, uploader, follow: :file_thumb_2, dependent: :destroy
|
74
|
+
end
|
75
|
+
|
76
|
+
expect(klass2.attached_files).to eq([:file, :file_thumb])
|
77
|
+
expect(klass2.attached_followers_per_leader).to eq({file: [:file_thumb]})
|
78
|
+
|
79
|
+
expect(klass3.attached_files).to eq([:file_thumb_2, :file_thumb_3])
|
80
|
+
expect(klass3.attached_followers_per_leader).to eq({file_thumb_2: [:file_thumb_3]})
|
81
|
+
end
|
33
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saviour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Campos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|