saviour 0.5.8 → 0.5.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f06409c24b72526d31e275f0960f5bf754013f3d53497a81a94bef09c574407
4
- data.tar.gz: 318b4ab1d8640c87302483853419b03cea9495af7e299c124f3fab8f6be5b8df
3
+ metadata.gz: f0747dcd299b6f0a1965c583f5f8b71a3c181355f7c98a36e180e5607172af79
4
+ data.tar.gz: 1aac6b08756d18cd88869e7fa3b25b798a4bc0d543d9ebabe57436ce4edb3f0d
5
5
  SHA512:
6
- metadata.gz: dcb4f0d8c74ff3d2bf6354c4012f65e5869009a75ca0d23b773156527767b880c2f328de365a6eb8dc5e371f074dedd37785436c545edf6f3fd034971f819acf
7
- data.tar.gz: ff1b6c64937fd164ab1bdc1e5e7d76c81d0116c303696c17b86b40f8514b6e9bb58de18b4fa53bcc79f6ec67a991c9878a6db0e396d06f4db2921c5b9fc6c9ad
6
+ metadata.gz: ca9ce86fa1f80542876bb174b4d74775e66849df6f067a4515fe0634d9936f69ac98b99bcf72a1c29181612a68a322241bf2d2b7f85ddc49f4af97984a0cf7a5
7
+ data.tar.gz: 2c9c98ae090b2fe969cd4e806cddfad8b86d53738d5096e87d6dd15d75f591148533fb117b6186bfb4a364443d7e774117157676644b9ac194d09a9c07f6413c
@@ -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
- klass.attached_files.push(attach_as)
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
- klass.followers_per_leader_config[opts[:follow]] ||= []
31
- klass.followers_per_leader_config[opts[:follow]].push({ attachment: attach_as, dependent: dependent })
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
- klass.include mod
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
- klass.__saviour_validations ||= Hash.new { [] }
107
- klass.__saviour_validations[attach_as] += [{ method_or_block: method_name || block, type: :memory }]
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
- klass.__saviour_validations ||= Hash.new { [] }
112
- klass.__saviour_validations[attach_as] += [{ method_or_block: method_name || block, type: :file }]
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
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.5.8"
2
+ VERSION = "0.5.9"
3
3
  end
@@ -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.8
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 00:00:00.000000000 Z
11
+ date: 2018-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord