Module: ActiveModelSerializers::Deprecate
- Included in:
- ActiveModel::SerializableResource, ActiveModel::Serializer, ActiveModel::Serializer::Adapter, ActiveModel::Serializer::Adapter::Attributes, ActiveModel::Serializer::Adapter::Base, ActiveModel::Serializer::Adapter::Json, ActiveModel::Serializer::Adapter::JsonApi, ActiveModel::Serializer::Adapter::Null, ActiveModel::Serializer::ArraySerializer
- Defined in:
- lib/active_model_serializers/deprecate.rb
Class Method Summary collapse
- .delegate_and_deprecate(method, delegee) ⇒ Object
-
.deprecate(name, replacement) ⇒ Object
Simple deprecation method that deprecates
name
by wrapping it up in a dummy method.
Class Method Details
.delegate_and_deprecate(method, delegee) ⇒ Object
48 49 50 51 |
# File 'lib/active_model_serializers/deprecate.rb', line 48 def delegate_and_deprecate(method, delegee) delegate method, to: delegee deprecate method, "#{delegee.name}." end |
.deprecate(name, replacement) ⇒ Object
Simple deprecation method that deprecates name
by wrapping it up in a dummy method. It warns on each call to the dummy method telling the user of replacement
(unless replacement
is :none) that it is planned to go away.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_model_serializers/deprecate.rb', line 33 def deprecate(name, replacement) old = "_deprecated_#{name}" alias_method old, name class_eval do define_method(name) do |*args, &block| target = is_a?(Module) ? "#{self}." : "#{self.class}#" msg = ["NOTE: #{target}#{name} is deprecated", replacement == :none ? ' with no replacement' : "; use #{replacement} instead", "\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(':')}"] warn "#{msg.join}." send old, *args, &block end end end |