lib/dir_model/export/files.rb in dir_model-0.5.1 vs lib/dir_model/export/files.rb in dir_model-0.5.2
- old
+ new
@@ -2,12 +2,12 @@
module Export
module Files
extend ActiveSupport::Concern
included do
- define_skip_method(self.file_name)
define_file_method(self.file_name)
+ define_skip_method(self.file_name)
define_extension_method(self.file_name)
end
module ClassMethods
@@ -15,11 +15,23 @@
#
# Define default skip method for a file
# @param file_name [Symbol] the file: name
def define_skip_method(file_name)
define_method(:skip?) do
- !self.public_send(file_name).try(:present?)
+ _file = self.public_send(file_name)
+
+ return true if _file.nil?
+ if _file.respond_to?(:exists?) # Carrierwave with remote file
+ return true unless _file.exists?
+ else
+ if _file.respond_to?(:path) # Locale file
+ return true unless File.exists?(_file.path)
+ end
+ end
+ return true unless _file.respond_to?(:read)
+
+ false
end
end
# Safe to override
#
@@ -48,11 +60,12 @@
protected
def file(file_name, options={})
super
- define_skip_method(file_name)
+
define_file_method(file_name)
+ define_skip_method(file_name)
define_extension_method(file_name)
end
end
end