From f86afae3f1bb4f0da26f6926f98dbf9b4904a84d Mon Sep 17 00:00:00 2001 From: Alexander Pauly Date: Wed, 13 Feb 2019 16:28:44 +0100 Subject: [PATCH] Small refactoring to allow custom handling for AR *_will_change callbacks --- lib/json_translate/translates/instance_methods.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/json_translate/translates/instance_methods.rb b/lib/json_translate/translates/instance_methods.rb index 68c2f19..c671b08 100644 --- a/lib/json_translate/translates/instance_methods.rb +++ b/lib/json_translate/translates/instance_methods.rb @@ -49,7 +49,7 @@ def write_json_translation(attr_name, value, locale = I18n.locale) value = value.presence translation_store = "#{attr_name}#{SUFFIX}" translations = public_send(translation_store) || {} - public_send("#{translation_store}_will_change!") unless translations[locale.to_s] == value + translation_store_will_change!(translation_store) unless translations[locale.to_s] == value if value translations[locale.to_s] = value else @@ -59,6 +59,10 @@ def write_json_translation(attr_name, value, locale = I18n.locale) value end + def translation_store_will_change!(translation_store) + public_send("#{translation_store}_will_change!") + end + def toggle_fallback(enabled) if block_given? old_value = @enabled_fallback