Skip to content

Commit

Permalink
Remove deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed Dec 4, 2018
1 parent 225520a commit ba24549
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 108 deletions.
47 changes: 1 addition & 46 deletions lib/mobility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ def extended(model_class)

model_class.extend Translates
model_class.extend ClassMethods
#TODO: Remove in v1.0
model_class.include InstanceMethods

if translates = Mobility.config.accessor_method
model_class.singleton_class.send(:alias_method, translates, :mobility_accessor)
Expand Down Expand Up @@ -183,12 +181,6 @@ def get_class_from_key(parent_class, key)
end
end

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

# TODO: Make private in v1.0
def new_fallbacks(*args)
config.public_send(:new_fallbacks, *args)
end
Expand Down Expand Up @@ -235,17 +227,7 @@ def normalize_locale_accessor(attribute, locale = Mobility.locale)
# @param [String,Symbol] locale
# @raise [InvalidLocale] if locale is present but not available
def enforce_available_locales!(locale)
# TODO: Remove conditional in v1.0
if I18n.enforce_available_locales
raise Mobility::InvalidLocale.new(locale) unless (locale.nil? || available_locales.include?(locale.to_sym))
else
warn <<-EOL
WARNING: You called Mobility.enforce_available_locales! in a situation where
I18n.enforce_available_locales is false. In the past, Mobility would do nothing
in this case, but as of the next major release Mobility will ignore the I18n
setting and enforce available locales whenever this method is called.
EOL
end
raise Mobility::InvalidLocale.new(locale) unless (locale.nil? || available_locales.include?(locale.to_sym))
end

# Returns available locales. Defaults to I18n.available_locales, but will
Expand Down Expand Up @@ -277,33 +259,6 @@ def set_locale(locale)
end
end

# TODO: Remove entire module in v1.0
module InstanceMethods
# Fetch backend for an attribute
# @deprecated Use mobility_backends[:<attribute>] instead.
# @param [String] attribute Attribute
def mobility_backend_for(attribute)
warn %{
WARNING: mobility_backend_for is deprecated and will be removed in the next
version of Mobility. Use <post>.<attribute>_backend instead.}
mobility_backends[attribute.to_sym]
end

def mobility
warn %{
WARNING: <post>.mobility is deprecated and will be removed in the next
version of Mobility. To get backends, use <post>.<attribute>_backend instead.}
@mobility ||= Adapter.new(self)
end

class Adapter < Struct.new(:model)
def backend_for(attribute)
model.mobility_backends[attribute.to_sym]
end
end
private_constant :Adapter
end

module ClassMethods
# Return translated attribute names on this model.
# @return [Array<String>] Attribute names
Expand Down
9 changes: 1 addition & 8 deletions lib/mobility/backends/key_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,7 @@ def configure(options)
options[:association_name] &&= options[:association_name].to_sym
options[:class_name] &&= Util.constantize(options[:class_name])
if !(options[:type] || (options[:class_name] && options[:association_name]))
# TODO: Remove warning and raise ArgumentError in v1.0
warn %{
WARNING: In previous versions, the Mobility KeyValue backend defaulted to a
text type column, but this behavior is now deprecated and will be removed in
the next release. Either explicitly specify the type by passing type: :text in
each translated model, or set a default option in your configuration.
}
options[:type] = :text
raise ArgumentError, "KeyValue backend requires an explicit type option, either text or string."
end
end

Expand Down
38 changes: 0 additions & 38 deletions lib/mobility/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@ class Configuration
# @return [Hash]
attr_reader :default_options

# @deprecated The default_options= setter has been deprecated. Set each
# option on the default_options hash instead.
def default_options=(options)
warn %{
WARNING: The default_options= setter has been deprecated.
Set each option on the default_options hash instead, like this:
config.default_options[:fallbacks] = { ... }
config.default_options[:dirty] = true
}
if (keys = options.keys & RESERVED_OPTION_KEYS).present?
raise ReservedOptionKey,
"Default options may not contain the following reserved keys: #{keys.join(', ')}"
else
@default_options = options
end
end

# @param [Symbol] name Plugin name
def plugin(name)
attributes_class.plugin(name)
Expand Down Expand Up @@ -68,26 +50,6 @@ def new_fallbacks(fallbacks = {})
# @param [Proc] fallbacks generator
attr_writer :fallbacks_generator

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

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

# Default backend to use (can be symbol or actual backend class)
# @return [Symbol,Class]
attr_accessor :default_backend
Expand Down
10 changes: 5 additions & 5 deletions spec/mobility/backends/key_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
klass
end

it "issues warning if type is not defined, and class_name and association_name are also not defined" do
it "raises ArgumentError if type is not defined, and class_name and association_name are also not defined" do
stub_const("Foo", Class.new)
error_regex = /#{%{WARNING: In previous versions, the Mobility KeyValue backend defaulted to a}}/
expect { backend_class.configure({}) }.to output(error_regex).to_stderr
expect { backend_class.configure(class_name: "Foo") }.to output(error_regex).to_stderr
expect { backend_class.configure(association_name: "foos") }.to output(error_regex).to_stderr
error_msg = /KeyValue backend requires an explicit type option/
expect { backend_class.configure({}) }.to raise_error(ArgumentError, error_msg)
expect { backend_class.configure(class_name: "Foo") }.to raise_error(ArgumentError, error_msg)
expect { backend_class.configure(association_name: "foos") }.to raise_error(ArgumentError, error_msg)
end
end
end
1 change: 0 additions & 1 deletion spec/mobility/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

it "initializes new fallbacks instance to I18n::Locale::Fallbacks.new" do
expect(subject.new_fallbacks).to be_a(I18n::Locale::Fallbacks)
expect(subject.default_fallbacks).to be_a(I18n::Locale::Fallbacks) # TODO: remove in v1.0
end

it "initializes default accessor_locales to I18n.available_locales" do
Expand Down
10 changes: 0 additions & 10 deletions spec/mobility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,4 @@ def perform_with_locale(locale)
}.to yield_with_args(described_class.config)
end
end

# TODO: remove default_fallbacks in v1.0
%w[accessor_method query_method default_fallbacks new_fallbacks default_accessor_locales].each do |delegated_method|
describe ".#{delegated_method}" do
it "delegates to config" do
expect(described_class.config).to receive(delegated_method).and_return("foo")
expect(described_class.send(delegated_method)).to eq("foo")
end
end
end
end

0 comments on commit ba24549

Please sign in to comment.