module KonoUtils::Concerns::ActiveStorageRemoverHelper::ClassMethods
included do
end
Public Instance Methods
attribute_purger_name(field)
click to toggle source
Nome dell'attributo da generare @param [String] field @return [Symbol]
# File lib/kono_utils/concerns/active_storage_remover_helper.rb, line 56 def attribute_purger_name(field) "kono_utils_purge_#{field}".to_sym end
has_one_attached_remover(field_name)
click to toggle source
Costruisce i metodi e attributi necessari al modello per gestire la rimozione attraverso l'interfaccia del file allegato @param [String,Symbol] field_name
# File lib/kono_utils/concerns/active_storage_remover_helper.rb, line 34 def has_one_attached_remover(field_name) attr = attribute_purger_name(field_name) callback = "make_#{attr}".to_sym attr_accessor attr after_save callback define_method(callback) do if self.send(attr.to_sym) == '1' if self.send(field_name.to_sym).attached? self.send(field_name.to_sym).purge_later end end end end