Skip to content

Commit

Permalink
Rename default_fallbacks to default_fallbacks_instance
Browse files Browse the repository at this point in the history
See #81.
  • Loading branch information
shioyama committed Dec 22, 2017
1 parent 358394b commit 4593613
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lib/mobility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def config
# (see Mobility::Configuration#query_method)
# @!method query_method

# (see Mobility::Configuration#default_fallbacks)
# @!method default_fallbacks
# (see Mobility::Configuration#default_fallbacks_instance)
# @!method default_fallbacks_instance

# (see Mobility::Configuration#default_backend)
# @!method default_backend
Expand All @@ -169,10 +169,15 @@ def config
end
end

# TODO: Remove in v1.0
define_method :default_fallbacks do |*args|
config.public_send(:default_fallbacks, *args)
end

define_method :default_fallbacks_instance do |*args|
config.public_send(:default_fallbacks_instance, *args)
end

# Configure Mobility
# @yield [Mobility::Configuration] Mobility configuration
def configure
Expand Down
35 changes: 31 additions & 4 deletions lib/mobility/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,39 @@ def default_options=(options)
# @return [Array<Symbol>]
attr_accessor :plugins

# Default fallbacks instance
# Call default fallbacks instance
# @note This method will *call* the proc defined in the variable set by the
# +default_fallbacks_instance=+ setter. By default this will return an
# instance of +I18n::Locale::Fallbacks+.
# @return [I18n::Locale::Fallbacks]
def default_fallbacks_instance(fallbacks = {})
@default_fallbacks_instance.call(fallbacks)
end

# Assign proc which, passed a set of fallbacks, returns a default fallbacks
# instance. By default this is a proc which takes fallbacks and returns an
# instance of +I18n::Locale::Fallbacks+.
attr_writer :default_fallbacks_instance

# @deprecated Use {#default_fallbacks_instance} instead.
def default_fallbacks(fallbacks = {})
@default_fallbacks.call(fallbacks)
warn %{
WARNING: The default_fallbacks configuration has been renamed
default_fallbacks_instance to avoid confusion. The original method
default_fallbacks will be removed in the next major version of Mobility.
}
default_fallbacks_instance(fallbacks = {})
end

# @deprecated Use {#default_fallbacks_instance=} instead.
def default_fallbacks=(fallbacks)
warn %{
WARNING: The default_fallbacks= configuration setter has been renamed
default_fallbacks_instance= to avoid confusion. The original method
default_fallbacks= will be removed in the next major version of Mobility.
}
default_fallbacks_instance=(fallbacks)
end
attr_writer :default_fallbacks

# Default backend to use (can be symbol or actual backend class)
# @return [Symbol,Class]
Expand All @@ -71,7 +98,7 @@ def default_accessor_locales
def initialize
@accessor_method = :translates
@query_method = :i18n
@default_fallbacks = lambda { |fallbacks| I18n::Locale::Fallbacks.new(fallbacks) }
@default_fallbacks_instance = lambda { |fallbacks| I18n::Locale::Fallbacks.new(fallbacks) }
@default_accessor_locales = lambda { I18n.available_locales }
@default_options = Options[{
cache: true,
Expand Down
10 changes: 5 additions & 5 deletions lib/mobility/plugins/fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module Plugins
given locale.
For +fallbacks: true+, Mobility will use the value of
{Mobility::Configuration#default_fallbacks} for the fallbacks instance. This
defaults to an instance of +I18n::Locale::Fallbacks+, but can be configured
(see {Mobility::Configuration}).
{Mobility::Configuration#default_fallbacks_instance} for the fallbacks
instance. This defaults to an instance of +I18n::Locale::Fallbacks+, but can be
configured (see {Mobility::Configuration}).
If a hash is passed to the +fallbacks+ option, a new fallbacks instance will be
created for the model with the hash defining additional fallbacks.
Expand Down Expand Up @@ -133,9 +133,9 @@ def define_read(fallbacks)

def convert_option_to_fallbacks(option)
if option.is_a?(Hash)
Mobility.default_fallbacks(option)
Mobility.default_fallbacks_instance(option)
elsif option == true
Mobility.default_fallbacks
Mobility.default_fallbacks_instance
else
Hash.new { [] }
end
Expand Down

0 comments on commit 4593613

Please sign in to comment.