card-mod-carrierwave 0.13.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7304e98064495ce7fd04793d2c5ba725a3d03badb878d8b7fb5a413cf28a71c
4
- data.tar.gz: ebcc5e035dea1a675d2372a2e062d8bf5fade776e65cd867721a251be863ff3d
3
+ metadata.gz: 74d69d0957e4946371f5aabcb6abaedd5f50123cbe70fbaa7b328817eaf08f32
4
+ data.tar.gz: 1d3c28ee81ab22e9ceb1aeec7676f82c5c8b4b86ef8b049e3edf624d43b3f3d6
5
5
  SHA512:
6
- metadata.gz: 2c47c08a8a7f0266be5138934258442158374fb4b7b6604d677df3294c33f2bb2a3d6c9b375224f39f67e8b478448bcca9e42165312e5dbb1b59a68150106963
7
- data.tar.gz: 3d5dc7e994acb72df1a2517328f7232babfa0271da38a4ed552a8f5a349ed53cc6dc1f9ee8c94becd03ce39f111c59c671ef0829b60ff593a694df930cbdcc91
6
+ metadata.gz: a632c57d6d8f90f337dae763b28ca1f31203ddd965df6c7e76fc153289db021801f740891029577eb4b97f2d166f9ca0c11ae0163fed8ac03df9bbf9435a12fd
7
+ data.tar.gz: '087cb9ac0b11218b8edc46c1f9502860f899edb13ed81eabcf910e6e9075f124320fef93cd894ff3dacee419b6799f6f36564a7759a1d83a50fc696d325ce924'
@@ -53,6 +53,7 @@ module CarrierWave
53
53
  end
54
54
 
55
55
  def store_attachment!
56
+ set_specific.delete :#{column}
56
57
  store_#{column}!
57
58
  end
58
59
 
@@ -7,7 +7,7 @@ module CarrierWave
7
7
  # path-related methods for uploader
8
8
  module Path
9
9
  def local_url opts={}
10
- "%s/%s/%s" % [local_url_base(opts), file_dir, full_filename(url_filename(opts))]
10
+ "%s/%s/%s" % [local_url_base(opts), file_dir, full_filename(url_filename)]
11
11
  end
12
12
 
13
13
  def local_url_base opts={}
@@ -145,7 +145,7 @@ module CarrierWave
145
145
 
146
146
  def filename
147
147
  if model.coded?
148
- "#{model.type_code}#{extension}"
148
+ "#{model.attachment_name}#{extension}"
149
149
  else
150
150
  "#{action_id}#{extension}"
151
151
  end
@@ -167,22 +167,18 @@ module CarrierWave
167
167
  # @option opts [Symbol] storage_type
168
168
  # @option opts [String] mod
169
169
  # @option opts [Symbol] bucket
170
- def db_content opts={}
171
- model.with_storage_options opts do
172
- return model.content if model.web?
173
- return "" unless file.present?
170
+ def db_content
171
+ return model.content if model.web?
172
+ return "" unless file.present?
174
173
 
175
- "%s/%s" % [file_dir, url_filename]
176
- end
174
+ "%s/%s" % [file_dir, url_filename]
177
175
  end
178
176
 
179
- def url_filename opts={}
180
- model.with_storage_options opts do
181
- if model.coded?
182
- "#{model.mod}#{extension}"
183
- else
184
- "#{action_id}#{extension}"
185
- end
177
+ def url_filename
178
+ if model.coded?
179
+ "#{model.mod}#{extension}"
180
+ else
181
+ "#{action_id}#{extension}"
186
182
  end
187
183
  end
188
184
 
@@ -206,7 +202,9 @@ module CarrierWave
206
202
  end
207
203
 
208
204
  def action_id
209
- model.selected_content_action_id || action_id_stand_in
205
+ model.selected_content_action_id ||
206
+ model.last_content_action_id ||
207
+ action_id_stand_in
210
208
  end
211
209
 
212
210
  # delegate carrierwave's fog config methods to bucket configuration
@@ -227,7 +225,7 @@ module CarrierWave
227
225
  # used as action_id in the filename
228
226
  # if card is not #actionable?
229
227
  def action_id_stand_in
230
- Time.now.to_i
228
+ @action_id_stand_in ||= Time.now.to_i
231
229
  end
232
230
 
233
231
  def storage
data/locales/de.yml ADDED
@@ -0,0 +1,13 @@
1
+ de:
2
+ carrierwave_add_item: "%{attachment_name} hinzufügen..."
3
+ carrierwave_codename_needed_for_storage: Codename erforderlich für Speichertyp coded
4
+ carrierwave_delete: Löschen
5
+ carrierwave_download: Download %{title}
6
+ carrierwave_error_invalid_storage_type: "%{type} ist keine gültige Dateispeicheroption"
7
+ carrierwave_file_error: Dateifehler
8
+ carrierwave_is_missing: fehlt
9
+ carrierwave_mod_argument_needed_to_save: mod-Argument erforderlich um Karte als coded zu speichern.
10
+ carrierwave_moving_files_is_not_supported: verschieben von Dateien aus einer Cloud wird nicht unterstützt
11
+ carrierwave_replace_item: Ersetze %{attachment_name}...
12
+ carrierwave_unknown_storage_type: unbekannter Speichertyp %{new_storage_type}
13
+ carrierwave_url_is_missing: Url fehlt
@@ -42,6 +42,7 @@ event :assign_attachment_on_update, :initialize,
42
42
  end
43
43
 
44
44
  def assign_attachment file, original_filename
45
+ @attaching = true
45
46
  send "#{attachment_name}=", file
46
47
  write_identifier
47
48
  @current_action&.update! comment: original_filename
@@ -63,7 +64,7 @@ end
63
64
 
64
65
  event :delete_cached_upload_file_on_update, :integrate,
65
66
  on: :update, when: :save_preliminary_upload? do
66
- return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
67
+ return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
67
68
 
68
69
  delete_files_for_action action
69
70
  action.delete
@@ -76,7 +77,7 @@ def upload_cache_card
76
77
  end
77
78
 
78
79
  def preliminary_upload?
79
- Card::Env && Card::Env.params[:attachment_upload]
80
+ Card::Env.params[:attachment_upload]
80
81
  end
81
82
 
82
83
  def save_preliminary_upload?
@@ -0,0 +1,105 @@
1
+ attr_writer :bucket, :new_storage_type
2
+
3
+ event :update_storage, :store, on: :update, when: :storage_changed? do
4
+ send "#{attachment_name}=", current.attachment.file unless @attaching
5
+ write_identifier
6
+ end
7
+
8
+ event :validate_storage_type, :validate, on: :save do
9
+ errors.add :storage_type, unknown_storage_type unless known_storage_type?
10
+ end
11
+
12
+ def current
13
+ @current ||= refresh true
14
+ end
15
+
16
+ def read_only?
17
+ web? || (cloud? && bucket_config[:read_only])
18
+ end
19
+
20
+ def cloud?
21
+ storage_type == :cloud
22
+ end
23
+
24
+ def web?
25
+ storage_type == :web
26
+ end
27
+
28
+ def local?
29
+ storage_type == :local
30
+ end
31
+
32
+ def coded?
33
+ storage_type == :coded
34
+ end
35
+
36
+ def remote_storage?
37
+ cloud? || web?
38
+ end
39
+
40
+ def storage_type= value
41
+ @explicit_storage_type = true
42
+ @storage_type = value&.to_sym
43
+ end
44
+
45
+ def storage_type
46
+ @storage_type ||= new_card? ? storage_type_from_config : storage_type_from_content
47
+ end
48
+
49
+ def storage_type_from_config
50
+ valid_storage_type ENV["FILE_STORAGE"] || Cardio.config.file_storage
51
+ end
52
+
53
+ def valid_storage_type storage_type
54
+ storage_type.to_sym.tap do |type|
55
+ invalid_storage_type! type unless type.in? valid_storage_type_list
56
+ end
57
+ end
58
+
59
+ def valid_storage_type_list
60
+ CarrierWave::FileCardUploader::STORAGE_TYPES
61
+ end
62
+
63
+ def invalid_storage_type! type
64
+ raise Card::Error, t(:carrierwave_error_invalid_storage_type, type: type)
65
+ end
66
+
67
+ def storage_type_from_content
68
+ @storage_type_from_content ||=
69
+ case content
70
+ when /^\(/ then :cloud
71
+ when %r{/^https?:/} then :web
72
+ when /^~/ then :local
73
+ when /^:/ then :coded
74
+ else
75
+ if deprecated_mod_file?
76
+ :coded
77
+ else
78
+ storage_type_from_config
79
+ end
80
+ end
81
+ end
82
+
83
+ def storage_changed?
84
+ (storage_type != current.storage_type) ||
85
+ (bucket != current.bucket) ||
86
+ (mod != current.mod)
87
+ end
88
+
89
+ def known_storage_type?
90
+ storage_type.in? CarrierWave::FileCardUploader::STORAGE_TYPES
91
+ end
92
+
93
+ def unknown_storage_type
94
+ t :carrierwave_unknown_storage_type, new_storage_type: storage_type
95
+ end
96
+
97
+ def file_updated_at
98
+ if coded?
99
+ File.mtime file.path
100
+ else
101
+ updated_at
102
+ end
103
+ rescue Errno::ENOENT # no file at path
104
+ nil
105
+ end
@@ -1,17 +1,8 @@
1
+ attr_writer :bucket
2
+
1
3
  event :change_bucket_if_read_only, :initialize,
2
4
  on: :update, when: :change_bucket_if_read_only? do
3
- @new_storage_type = storage_type_from_config
4
- end
5
-
6
- event :validate_storage_type_update, :validate, on: :update, when: :cloud? do
7
- # FIXME: make it possible to retrieve the file from cloud storage
8
- # to store it somewhere else. Currently, it only works to change the
9
- # storage type if a new file is provided
10
- # i.e. `update storage_type: :local` fails but
11
- # `update storage_type: :local, file: [file handle]` is ok
12
- return unless storage_type_changed? && !attachment_is_changing?
13
-
14
- errors.add :storage_type, t(:carrierwave_moving_files_is_not_supported)
5
+ @storage_type = storage_type_from_config
15
6
  end
16
7
 
17
8
  def bucket
@@ -127,11 +118,3 @@ end
127
118
  def change_bucket_if_read_only?
128
119
  cloud? && bucket_config[:read_only] && attachment_is_changing?
129
120
  end
130
-
131
- def bucket= value
132
- if @action == :update
133
- @new_bucket = value
134
- else
135
- @bucket = value
136
- end
137
- end
@@ -1,27 +1,62 @@
1
- event :lose_coded_status_on_update, :initialize, on: :update, when: :coded? do
2
- # unless explicit
3
- return if @new_mod
1
+ MOD_FILE_DIR = "data/files".freeze
4
2
 
5
- @new_storage_type ||= storage_type_from_config
3
+ event :uncode_attachment_storage, :initialize, on: :update, when: :uncode? do
4
+ @storage_type = storage_type_from_config unless @explicit_storage_type
6
5
  end
7
6
 
8
- event :validate_coded_storage_type, :validate, on: :save, when: :will_become_coded? do
9
- storage_type_error :mod_argument_needed_to_save unless mod || @new_mod
7
+ event :validate_coded_storage_type, :validate, on: :save, when: :coded? do
8
+ storage_type_error :mod_argument_needed_to_save unless mod
10
9
  storage_type_error :codename_needed_for_storage if codename.blank?
11
10
  end
12
11
 
13
- def storage_type_error error_name
14
- errors.add :storage_type, t("carrierwave_#{error_name}")
12
+ def mod= value
13
+ @mod = value.to_s
15
14
  end
16
15
 
17
- def will_become_coded?
18
- will_be_stored_as == :coded
16
+ def mod
17
+ @mod ||= coded? && mod_from_content
19
18
  end
20
19
 
21
- def mod= value
22
- if @action == :update && mod != value
23
- @new_mod = value.to_s
20
+ private
21
+
22
+ def uncode?
23
+ (@explicit_storage_type != :coded) && !set_specific[:mod].present? && current.coded?
24
+ # (@explicit_storage_type != :coded) && !mod && current.coded?
25
+ end
26
+
27
+ def storage_type_error error_name
28
+ errors.add :storage_type, t("carrierwave_#{error_name}")
29
+ end
30
+
31
+ def mod_from_content
32
+ if (m = content.match %r{^:[^/]+/([^.]+)})
33
+ m[1] # current mod_file format
24
34
  else
25
- @mod = value.to_s
35
+ mod_from_deprecated_content
26
36
  end
27
37
  end
38
+
39
+ # place for files of mod file cards
40
+ def coded_dir new_mod=nil
41
+ dir = File.join mod_dir(new_mod), MOD_FILE_DIR, codename.to_s
42
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
43
+ dir
44
+ end
45
+
46
+ def mod_dir new_mod=nil
47
+ mod_name = new_mod || mod
48
+ dir = Cardio::Mod.dirs.path(mod_name) || (mod_name.to_sym == :test && "test")
49
+
50
+ raise Error, "can't find mod \"#{mod_name}\"" unless dir
51
+
52
+ dir
53
+ end
54
+
55
+ def deprecated_mod_file?
56
+ content.present? && !content.match?(/^~/) && content.split("\n")&.size == 4
57
+ end
58
+
59
+ # old format is still used in card_changes
60
+ def mod_from_deprecated_content
61
+ content.split("\n").last if deprecated_mod_file?
62
+ end
@@ -1,7 +1,5 @@
1
- MOD_FILE_DIR = "file".freeze
2
-
3
1
  def store_dir
4
- will_become_coded? ? coded_dir(@new_mod) : upload_dir
2
+ coded? ? coded_dir : upload_dir
5
3
  end
6
4
 
7
5
  def retrieve_dir
@@ -13,22 +11,6 @@ def upload_dir
13
11
  id ? "#{files_base_dir}/#{id}" : tmp_upload_dir
14
12
  end
15
13
 
16
- # place for files of mod file cards
17
- def coded_dir new_mod=nil
18
- dir = File.join mod_dir(new_mod), MOD_FILE_DIR, codename.to_s
19
- FileUtils.mkdir_p(dir) unless File.directory?(dir)
20
- dir
21
- end
22
-
23
- def mod_dir new_mod=nil
24
- mod_name = new_mod || mod
25
- dir = Cardio::Mod.dirs.path(mod_name) || (mod_name.to_sym == :test && "test")
26
-
27
- raise Error, "can't find mod \"#{mod_name}\"" unless dir
28
-
29
- dir
30
- end
31
-
32
14
  def files_base_dir
33
15
  dir = bucket ? bucket_config[:subdirectory] : Card.paths["files"].existent.first
34
16
  dir || files_base_dir_configuration_error
@@ -11,7 +11,7 @@ end
11
11
  # we need a card id for the path so we have to update db_content when we have
12
12
  # an id
13
13
  event :correct_identifier, :finalize, on: :create, when: proc { |c| !c.web? } do
14
- update_column(:db_content, attachment.db_content)
14
+ update_column :db_content, attachment.db_content
15
15
  expire
16
16
  end
17
17
 
@@ -24,7 +24,7 @@ end
24
24
  event :validate_file_exist, :validate, on: :create do
25
25
  return if empty_ok?
26
26
 
27
- if will_be_stored_as == :web
27
+ if web?
28
28
  errors.add "url is missing" if content.blank?
29
29
  elsif !attachment.file.present?
30
30
  errors.add attachment_name, "is missing"
@@ -54,7 +54,7 @@ def original_filename
54
54
  end
55
55
 
56
56
  def unfilled?
57
- !attachment.present? && !save_preliminary_upload? && !subcards? && blank_content?
57
+ !attachment.present? && !save_preliminary_upload? && super
58
58
  end
59
59
 
60
60
  def attachment_changed?
@@ -78,8 +78,9 @@ def empty_ok?
78
78
  end
79
79
 
80
80
  def assign_set_specific_attributes
81
+ @attaching = set_specific[attachment_name].present?
81
82
  # reset content if we really have something to upload
82
- self.content = nil if set_specific[attachment_name].present?
83
+ self.content = nil if @attaching
83
84
  super
84
85
  end
85
86
 
data/set/type/file.rb CHANGED
@@ -8,8 +8,6 @@ module SelectedAction
8
8
  end
9
9
 
10
10
  def last_content_action_id
11
- return super if temporary_storage_type_change?
12
-
13
11
  # find action id from content (saves lookups)
14
12
  db_content.to_s.split(%r{[/.]})[-2]
15
13
  end
data/set/type/image.rb CHANGED
@@ -21,7 +21,7 @@ format do
21
21
  render_core size: :icon
22
22
  end
23
23
 
24
- view :source do
24
+ view :source, unknown: :blank do
25
25
  return card.content if card.web?
26
26
 
27
27
  image = selected_version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.4
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-09-24 00:00:00.000000000 Z
13
+ date: 2021-12-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.103.4
21
+ version: 1.104.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.103.4
28
+ version: 1.104.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: carrierwave
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -60,28 +60,28 @@ dependencies:
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.13.4
63
+ version: 0.14.0
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.13.4
70
+ version: 0.14.0
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: card-mod-permissions
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.13.4
77
+ version: 0.14.0
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - '='
83
83
  - !ruby/object:Gem::Version
84
- version: 0.13.4
84
+ version: 0.14.0
85
85
  description: ''
86
86
  email:
87
87
  - info@decko.org
@@ -95,14 +95,15 @@ files:
95
95
  - lib/carrier_wave/file_card_uploader.rb
96
96
  - lib/carrier_wave/file_card_uploader/path.rb
97
97
  - lib/carrier_wave/image_card_uploader.rb
98
+ - locales/de.yml
98
99
  - locales/en.yml
99
100
  - set/abstract/attachment.rb
101
+ - set/abstract/attachment/00_upload_cache.rb
102
+ - set/abstract/attachment/01_storage_type.rb
100
103
  - set/abstract/attachment/cloud.rb
101
104
  - set/abstract/attachment/coded.rb
102
105
  - set/abstract/attachment/local.rb
103
106
  - set/abstract/attachment/paths.rb
104
- - set/abstract/attachment/storage_type.rb
105
- - set/abstract/attachment/upload_cache.rb
106
107
  - set/abstract/attachment/web.rb
107
108
  - set/all/file_utils.rb
108
109
  - set/self/admin.rb
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
141
  - !ruby/object:Gem::Version
141
142
  version: '0'
142
143
  requirements: []
143
- rubygems_version: 3.1.6
144
+ rubygems_version: 3.2.15
144
145
  signing_key:
145
146
  specification_version: 4
146
147
  summary: File and Image handling
@@ -1,171 +0,0 @@
1
- attr_writer :bucket, :new_storage_type
2
-
3
- event :storage_type_change, :store, on: :update, when: :storage_type_changed? do
4
- # carrierwave stores file if @cache_id is not nil
5
- attachment.cache_stored_file!
6
- # attachment.retrieve_from_cache!(attachment.cache_name)
7
- update_storage_attributes
8
- # next line might be necessary to move files to cloud
9
-
10
- # make sure that we get the new identifier
11
- # otherwise action_id will return wrong id for new identifier
12
- db_content_will_change!
13
- write_identifier
14
- end
15
-
16
- event :validate_storage_type, :validate, on: :save do
17
- return if known_storage_type? will_be_stored_as
18
-
19
- errors.add :storage_type, unknown_storage_type(@new_storage_type)
20
- end
21
-
22
- def will_be_stored_as
23
- @new_storage_type || storage_type
24
- end
25
-
26
- def read_only?
27
- web? || (cloud? && bucket_config[:read_only])
28
- end
29
-
30
- def cloud?
31
- storage_type == :cloud
32
- end
33
-
34
- def web?
35
- storage_type == :web
36
- end
37
-
38
- def local?
39
- storage_type == :local
40
- end
41
-
42
- def coded?
43
- storage_type == :coded
44
- end
45
-
46
- def remote_storage?
47
- cloud? || web?
48
- end
49
-
50
- def storage_type
51
- @storage_type ||=
52
- new_card? ? storage_type_from_config : storage_type_from_content
53
- end
54
-
55
- def deprecated_mod_file?
56
- content && (lines = content.split("\n")) && lines.size == 4
57
- end
58
-
59
- def mod
60
- @mod ||= coded? && mod_from_content
61
- end
62
-
63
- def mod_from_content
64
- if (m = content.match %r{^:[^/]+/([^.]+)})
65
- m[1] # current mod_file format
66
- else
67
- mod_from_deprecated_content
68
- end
69
- end
70
-
71
- # old format is still used in card_changes
72
- def mod_from_deprecated_content
73
- return if content.match?(/^~/)
74
- return unless (lines = content.split("\n")) && lines.size == 4
75
-
76
- lines.last
77
- end
78
-
79
- def storage_type_from_config
80
- valid_storage_type ENV["FILE_STORAGE"] || Cardio.config.file_storage
81
- end
82
-
83
- def valid_storage_type storage_type
84
- storage_type.to_sym.tap do |type|
85
- invalid_storage_type! type unless type.in? valid_storage_type_list
86
- end
87
- end
88
-
89
- def valid_storage_type_list
90
- CarrierWave::FileCardUploader::STORAGE_TYPES
91
- end
92
-
93
- def invalid_storage_type! type
94
- raise Card::Error, t(:carrierwave_error_invalid_storage_type, type: type)
95
- end
96
-
97
- def storage_type_from_content
98
- case content
99
- when /^\(/ then :cloud
100
- when %r{/^https?:/} then :web
101
- when /^~/ then :local
102
- when /^:/ then :coded
103
- else
104
- if deprecated_mod_file?
105
- :coded
106
- else
107
- storage_type_from_config
108
- end
109
- end
110
- end
111
-
112
- def update_storage_attributes
113
- @mod = @new_mod if @new_mod
114
- @bucket = @new_bucket if @new_bucket
115
- @storage_type = @new_storage_type
116
- end
117
-
118
- def storage_type_changed?
119
- @new_bucket || (@new_storage_type && @new_storage_type != storage_type) || @new_mod
120
- end
121
-
122
- def storage_type= value
123
- known_storage_type? value
124
- if @action == :update # && storage_type != value
125
- # we cant update the storage type directly here
126
- # if we do then the uploader doesn't find the file we want to update
127
- @new_storage_type = value
128
- else
129
- @storage_type = value
130
- end
131
- end
132
-
133
- def with_storage_options opts={}
134
- old_values = stash_and_set_storage_options opts
135
- validate_temporary_storage_type_change opts[:storage_type]
136
- @temp_storage_type = true
137
- yield
138
- ensure
139
- @temp_storage_type = false
140
- old_values.each { |key, val| instance_variable_set "@#{key}", val }
141
- end
142
-
143
- def stash_and_set_storage_options opts
144
- %i[storage_type mod bucket].each_with_object({}) do |opt_name, old_values|
145
- next unless opts[opt_name]
146
-
147
- old_values[opt_name] = instance_variable_get "@#{opt_name}"
148
- instance_variable_set "@#{opt_name}", opts[opt_name]
149
- old_values
150
- end
151
- end
152
-
153
- def temporary_storage_type_change?
154
- @temp_storage_type
155
- end
156
-
157
- def validate_temporary_storage_type_change type=nil
158
- return unless type ||= @new_storage_type
159
- raise Error, unknown_storage_type(type) unless known_storage_type? type
160
- if type == :coded && codename.blank?
161
- raise Error, "codename needed for storage type :coded"
162
- end
163
- end
164
-
165
- def known_storage_type? type=storage_type
166
- type.in? CarrierWave::FileCardUploader::STORAGE_TYPES
167
- end
168
-
169
- def unknown_storage_type type
170
- t :carrierwave_unknown_storage_type, new_storage_type: type
171
- end