summaryrefslogtreecommitdiff
path: root/lib/chef/mixin/deprecation.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/mixin/deprecation.rb')
-rw-r--r--lib/chef/mixin/deprecation.rb45
1 files changed, 22 insertions, 23 deletions
diff --git a/lib/chef/mixin/deprecation.rb b/lib/chef/mixin/deprecation.rb
index 04c40dcf29..0f059a215f 100644
--- a/lib/chef/mixin/deprecation.rb
+++ b/lib/chef/mixin/deprecation.rb
@@ -19,10 +19,9 @@
class Chef
module Mixin
-
- def self.deprecated_constants
- @deprecated_constants ||= {}
- end
+ def self.deprecated_constants
+ @deprecated_constants ||= {}
+ end
# Add a deprecated constant to the Chef::Mixin namespace.
# === Arguments
@@ -33,34 +32,34 @@ class Chef
# deprecate_constant(:RecipeDefinitionDSLCore, Chef::DSL::Recipe, <<-EOM)
# Chef::Mixin::RecipeDefinitionDSLCore is deprecated, use Chef::DSL::Recipe instead.
# EOM
- def self.deprecate_constant(name, replacement, message)
- deprecated_constants[name] = {:replacement => replacement, :message => message}
- end
+ def self.deprecate_constant(name, replacement, message)
+ deprecated_constants[name] = { :replacement => replacement, :message => message }
+ end
# Const missing hook to look up deprecated constants defined with
# deprecate_constant. Emits a warning to the logger and returns the
# replacement constant. Will call super, most likely causing an exception
# for the missing constant, if +name+ is not found in the
# deprecated_constants collection.
- def self.const_missing(name)
- if new_const = deprecated_constants[name]
- Chef::Log.warn(new_const[:message])
- Chef::Log.warn("Called from: \n#{caller[0...3].map {|l| "\t#{l}"}.join("\n")}")
- new_const[:replacement]
- else
- super
- end
+ def self.const_missing(name)
+ if new_const = deprecated_constants[name]
+ Chef::Log.warn(new_const[:message])
+ Chef::Log.warn("Called from: \n#{caller[0...3].map { |l| "\t#{l}" }.join("\n")}")
+ new_const[:replacement]
+ else
+ super
end
+ end
module Deprecation
class DeprecatedObjectProxyBase
KEEPERS = %w{__id__ __send__ instance_eval == equal? initialize object_id}
- instance_methods.each { |method_name| undef_method(method_name) unless KEEPERS.include?(method_name.to_s)}
+ instance_methods.each { |method_name| undef_method(method_name) unless KEEPERS.include?(method_name.to_s) }
end
class DeprecatedInstanceVariable < DeprecatedObjectProxyBase
- def initialize(target, ivar_name, level=nil)
+ def initialize(target, ivar_name, level = nil)
@target, @ivar_name = target, ivar_name
@level ||= :warn
end
@@ -80,7 +79,7 @@ class Chef
called_from = called_from.flatten
log("Accessing #{@ivar_name} by the variable @#{@ivar_name} is deprecated. Support will be removed in a future release.")
log("Please update your cookbooks to use #{@ivar_name} in place of @#{@ivar_name}. Accessed from:")
- called_from.each {|l| log(l)}
+ called_from.each { |l| log(l) }
end
def log(msg)
@@ -91,7 +90,7 @@ class Chef
end
- def deprecated_ivar(obj, name, level=nil)
+ def deprecated_ivar(obj, name, level = nil)
DeprecatedInstanceVariable.new(obj, name, level)
end
@@ -100,22 +99,22 @@ class Chef
deprecated_attr_writer(name, alternative)
end
- def deprecated_attr_reader(name, alternative, level=:warn)
+ def deprecated_attr_reader(name, alternative, level = :warn)
define_method(name) do
Chef.log_deprecation("#{self.class}.#{name} is deprecated. Support will be removed in a future release.")
Chef.log_deprecation(alternative)
Chef.log_deprecation("Called from:")
- caller[0..3].each {|c| Chef.log_deprecation(c)}
+ caller[0..3].each { |c| Chef.log_deprecation(c) }
instance_variable_get("@#{name}")
end
end
- def deprecated_attr_writer(name, alternative, level=:warn)
+ def deprecated_attr_writer(name, alternative, level = :warn)
define_method("#{name}=") do |value|
Chef.log_deprecation("Writing to #{self.class}.#{name} with #{name}= is deprecated. Support will be removed in a future release.")
Chef.log_deprecation(alternative)
Chef.log_deprecation("Called from:")
- caller[0..3].each {|c| Chef.log_deprecation(c)}
+ caller[0..3].each { |c| Chef.log_deprecation(c) }
instance_variable_set("@#{name}", value)
end
end