Module: FHIR::Deprecate

Included in:
Boot::Template, Definitions, Model, StructureDefinition, Xml
Defined in:
lib/fhir_models/deprecate.rb

Overview

add support for deprecating instance and class methods

Instance Method Summary collapse

Instance Method Details

#deprecate(old_method, new_method) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fhir_models/deprecate.rb', line 4

def deprecate(old_method, new_method)
  if instance_methods.include? new_method
    define_method(old_method) do |*args, &block|
      message = "DEPRECATED: `#{old_method}` has been deprecated. Use `#{new_method}` instead. Called from #{caller.first}"
      FHIR.logger.warn message
      send(new_method, *args, &block)
    end
  end
  return unless methods.include? new_method
  (class << self; self; end).instance_eval do
    define_method(old_method) do |*args, &block|
      message = "DEPRECATED: `#{old_method}` has been deprecated. Use `#{new_method}` instead. Called from #{caller.first}"
      FHIR.logger.warn message
      send(new_method, *args, &block)
    end
  end
end