Skip to content

Commit

Permalink
see if changing logic a little bit fixes specs
Browse files Browse the repository at this point in the history
  • Loading branch information
doits committed Jul 30, 2019
1 parent a18b8f9 commit 24f06ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/mobility/plugins/fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,21 @@ def define_read(fallbacks)
return super(locale, options) if !fallback || options[:locale]

fallback_locales =
if fallback == true
if fallbacks.is_a?(Proc)
model.instance_exec(&fallbacks)
Util.array_wrap(
if fallback == true
if fallbacks.is_a?(Proc)
model.instance_exec(&fallbacks)
else
fallbacks[locale]
end
elsif fallback.is_a?(Proc)
model.instance_exec(&fallback)
else
fallbacks[locale]
fallback
end
elsif fallback.is_a?(Proc)
model.instance_exec(&fallback)
else
fallback
end

locales = [locale, *fallback_locales]
locales.each do |fallback_locale|
)

fallback_locales.each do |fallback_locale|
value = super(fallback_locale, options)
return value if Util.present?(value)
end
Expand Down
11 changes: 11 additions & 0 deletions lib/mobility/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ def presence(object)
object if present?(object)
end

# taken from https://github.com/rails/rails/blob/6-0-stable/activesupport/lib/active_support/core_ext/array/wrap.rb
def array_wrap(object)
if object.nil?
[]
elsif object.respond_to?(:to_ary)
object.to_ary || [object]
else
[object]
end
end

private

# Calls caller method on object if defined, otherwise yields to block
Expand Down

0 comments on commit 24f06ec

Please sign in to comment.