about summary refs log tree commit diff
path: root/app/models/concerns
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-07-11 17:25:49 +0200
committerGitHub <noreply@github.com>2017-07-11 17:25:49 +0200
commite6c81a635b99dcec4f8fded00d9451cb876df822 (patch)
tree37e81b36d0739181bd75c78d0d80a48eb325a2bb /app/models/concerns
parentf93de3a516d23cddea7cce147d3da3decac85f2f (diff)
Fix #2848 - Rake task to redownload avatars/headers (#4156)
Can be filtered by a specific domain
Resolves #2292
Diffstat (limited to 'app/models/concerns')
-rw-r--r--app/models/concerns/remotable.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/models/concerns/remotable.rb b/app/models/concerns/remotable.rb
index 08d4fc59c..b4f169649 100644
--- a/app/models/concerns/remotable.rb
+++ b/app/models/concerns/remotable.rb
@@ -6,8 +6,9 @@ module Remotable
 
   included do
     attachment_definitions.each_key do |attachment_name|
-      attribute_name = "#{attachment_name}_remote_url".to_sym
-      method_name = "#{attribute_name}=".to_sym
+      attribute_name  = "#{attachment_name}_remote_url".to_sym
+      method_name     = "#{attribute_name}=".to_sym
+      alt_method_name = "reset_#{attachment_name}!".to_sym
 
       define_method method_name do |url|
         begin
@@ -35,6 +36,15 @@ module Remotable
           nil
         end
       end
+
+      define_method alt_method_name do
+        url = self[attribute_name]
+
+        return if url.blank?
+
+        self[attribute_name] = ''
+        send(method_name, url)
+      end
     end
   end
 end