model_attachment 0.0.21 → 0.0.24

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.
@@ -220,24 +220,19 @@ module ModelAttachment
220
220
  # save the correct attribute info before the save
221
221
  def save_attributes
222
222
  return if file_name.nil? || file_name.class.to_s == "String"
223
- # this used to be @temp_file = self.file_name but some change must have happened between 3.0.1 and 3.0.5
224
- @temp_file = (self.file_name.class == "ActionDispatch::Http::UploadedFile" ? self.file_name.tempfile : self.file_name)
223
+ # ensure we save the tempfile before overwriting file_name
224
+ @temp_file = self.file_name.tempfile
225
225
 
226
226
  # get original filename info and clean up for storage
227
- filename = File.basename(@temp_file)
228
- if @temp_file.original_filename
229
- filename = @temp_file.original_filename
230
- end
231
-
227
+ filename = (self.file_name.respond_to?(:original_filename) ? File.basename(self.file_name.original_filename) : File.basename(self.file_name))
232
228
  ext = File.extname(filename)
233
229
  base = File.basename(filename, ext).strip.gsub(/[^A-Za-z\d\.\-_]+/, '_')
234
230
 
235
231
  # save attributes
232
+ self.content_type = self.file_name.content_type.strip
233
+ self.file_size = self.file_name.tempfile.size.to_i
236
234
  self.file_name = base + ext
237
- self.content_type = @temp_file.content_type.strip
238
- self.file_size = @temp_file.size.to_i
239
- self.updated_at = Time.now
240
-
235
+ self.updated_at = Time.now
241
236
  end
242
237
 
243
238
  # Does all the file processing, moves from temp, processes images
@@ -1,3 +1,3 @@
1
1
  module ModelAttachment
2
- VERSION = "0.0.21"
2
+ VERSION = "0.0.24"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: model_attachment
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.21
5
+ version: 0.0.24
6
6
  platform: ruby
7
7
  authors:
8
8
  - Steve Walker
@@ -58,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- hash: -3972700263241288820
61
+ hash: 3080609047319991630
62
62
  segments:
63
63
  - 0
64
64
  version: "0"