Module: ActiveModelSerializers::Deprecate

Class Method Summary collapse

Class Method Details

.delegate_and_deprecate(method, delegee) ⇒ Object


46
47
48
49
# File 'lib/active_model_serializers/deprecate.rb', line 46

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.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_model_serializers/deprecate.rb', line 31

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