Skip to content

Commit

Permalink
Merge pull request #14 from apauly/feature/will_change_callbacks
Browse files Browse the repository at this point in the history
Small refactoring to allow custom handling for AR *_will_change callbacks
  • Loading branch information
frantisekrokusek authored Jan 5, 2021
2 parents 613858b + f86afae commit d146557
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/json_translate/translates/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def write_json_translation(attr_name, value, locale = I18n.locale, allow_blank:
value = allow_blank ? 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
Expand All @@ -59,6 +59,10 @@ def write_json_translation(attr_name, value, locale = I18n.locale, allow_blank:
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
Expand Down

0 comments on commit d146557

Please sign in to comment.