Module: Dry::Core::Deprecations::Interface
- Defined in:
- lib/dry/core/deprecations.rb
Instance Method Summary collapse
-
#deprecate(old_name, new_name = nil, message: nil) ⇒ Object
Mark instance method as deprecated.
-
#deprecate_class_method(old_name, new_name = nil, message: nil) ⇒ Object
Mark class-level method as deprecated.
-
#deprecation_tag(tag = nil) ⇒ Object
Sets/gets deprecation tag.
-
#warn(msg) ⇒ Object
Issue a tagged warning message.
Instance Method Details
#deprecate(old_name, new_name = nil, message: nil) ⇒ Object
Mark instance method as deprecated
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/dry/core/deprecations.rb', line 150 def deprecate(old_name, new_name = nil, message: nil) full_msg = Deprecations.( "#{self.name}##{old_name}", new_name ? "#{self.name}##{new_name}" : nil, ) mod = self if new_name undef_method old_name if method_defined?(old_name) define_method(old_name) do |*args, &block| mod.warn(full_msg) __send__(new_name, *args, &block) end else aliased_name = :"#{old_name}_without_deprecation" alias_method aliased_name, old_name private aliased_name undef_method old_name define_method(old_name) do |*args, &block| mod.warn(full_msg) __send__(aliased_name, *args, &block) end end end |
#deprecate_class_method(old_name, new_name = nil, message: nil) ⇒ Object
Mark class-level method as deprecated
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/dry/core/deprecations.rb', line 183 def deprecate_class_method(old_name, new_name = nil, message: nil) full_msg = Deprecations.( "#{self.name}.#{old_name}", new_name ? "#{self.name}.#{new_name}" : nil, ) meth = new_name ? method(new_name) : method(old_name) singleton_class.instance_exec do undef_method old_name if method_defined?(old_name) define_method(old_name) do |*args, &block| warn(full_msg) meth.call(*args, &block) end end end |
#deprecation_tag(tag = nil) ⇒ Object
Sets/gets deprecation tag
130 131 132 133 134 135 136 |
# File 'lib/dry/core/deprecations.rb', line 130 def deprecation_tag(tag = nil) if defined?(@deprecation_tag) @deprecation_tag else @deprecation_tag = tag end end |
#warn(msg) ⇒ Object
Issue a tagged warning message
141 142 143 |
# File 'lib/dry/core/deprecations.rb', line 141 def warn(msg) Deprecations.warn(msg, tag: deprecation_tag) end |