Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 8765bbe + 35315fc commit bcb78d8a5237d25fead57ef82b64b26e75830c8d Michael van Rooijen committed Nov 17, 2012
View
@@ -167,9 +167,7 @@ Backup::Model.new(:sample_backup, 'A sample backup configuration') do
encryption.password = 'my_secret_password'
end
- compress_with Gzip do |compression|
- compression.best = true
- end
+ compress_with Gzip
store_with SFTP, "Server A" do |server|
server.username = 'my_username'
@@ -5,6 +5,8 @@ module CLI
module Helpers
UTILITY = {}
+ private
+
##
# Runs a system command
#
@@ -38,17 +38,17 @@ def perform
Config.update(options)
##
- # Load the configuration file
- Config.load_config!
-
- ##
# Ensure the :log_path, :cache_path and :tmp_path are created
# if they do not yet exist
[Config.log_path, Config.cache_path, Config.tmp_path].each do |path|
FileUtils.mkdir_p(path)
end
##
+ # Load the configuration file
+ Config.load_config!
+
+ ##
# Truncate log file if needed
Logger.truncate!
@@ -16,11 +16,15 @@ class Bzip2 < Base
attr_accessor :level
attr_deprecate :fast, :version => '3.0.24',
- :replacement => :level,
- :value => lambda {|val| val ? 1 : nil }
+ :message => 'Use Bzip2#level instead.',
+ :action => lambda {|klass, val|
+ klass.level = 1 if val
+ }
attr_deprecate :best, :version => '3.0.24',
- :replacement => :level,
- :value => lambda {|val| val ? 9 : nil }
+ :message => 'Use Bzip2#level instead.',
+ :action => lambda {|klass, val|
+ klass.level = 9 if val
+ }
##
# Creates a new instance of Backup::Compressor::Bzip2
@@ -16,11 +16,15 @@ class Gzip < Base
attr_accessor :level
attr_deprecate :fast, :version => '3.0.24',
- :replacement => :level,
- :value => lambda {|val| val ? 1 : nil }
+ :message => 'Use Gzip#level instead.',
+ :action => lambda {|klass, val|
+ klass.level = 1 if val
+ }
attr_deprecate :best, :version => '3.0.24',
- :replacement => :level,
- :value => lambda {|val| val ? 9 : nil }
+ :message => 'Use Gzip#level instead.',
+ :action => lambda {|klass, val|
+ klass.level = 9 if val
+ }
##
# Creates a new instance of Backup::Compressor::Gzip
@@ -34,12 +34,9 @@ def deprecations
end
def log_deprecation_warning(name, deprecation)
- msg = "#{ self }.#{ name } has been deprecated as of " +
+ msg = "#{ self }##{ name } has been deprecated as of " +
"backup v.#{ deprecation[:version] }"
- if replacement = deprecation[:replacement]
- msg << "\nThis setting has been replaced with:\n" +
- "#{ self }.#{ replacement }"
- end
+ msg << "\n#{ deprecation[:message] }" if deprecation[:message]
Logger.warn Backup::Errors::ConfigurationError.new <<-EOS
[DEPRECATION WARNING]
#{ msg }
@@ -51,25 +48,29 @@ def log_deprecation_warning(name, deprecation)
##
# Method to deprecate an attribute.
#
- # :version should be set to the backup version which will first
+ # :version
+ # Must be set to the backup version which will first
# introduce the deprecation.
- # :replacement may be set to another attr_accessor name to set
- # the value for instead of the deprecated accessor
- # :value may be used to specify the value set on :replacement.
- # If :value is nil, the value set on the deprecated accessor
- # will be used to set the value for the :replacement.
- # If :value is a lambda, it will be passed the value the user
- # set on the deprecated accessor, and should return the value
- # to be set on the :replacement.
- # Therefore, to cause the replacement accessor not to be set,
- # use the lambda form to return nil. This is only way to specify
- # a :replacement without transferring a value.
- # e.g. :replacement => :new_attr, :value => Proc.new {}
+ #
+ # :action
+ # If set, this Proc will be called with a reference to the
+ # class instance and the value set on the deprecated accessor.
+ # e.g. deprecation[:action].call(klass, value)
+ # This should perform whatever action is neccessary, such as
+ # transferring the value to a new accessor.
+ #
+ # :message
+ # If set, this will be appended to #log_deprecation_warning
+ #
+ # Note that this replaces the `attr_accessor` method, or other
+ # method previously used to set the accessor being deprecated.
+ # #method_missing will handle any calls to `name=`.
+ #
def attr_deprecate(name, args = {})
deprecations[name] = {
:version => nil,
- :replacement => nil,
- :value => nil
+ :message => nil,
+ :action => nil
}.merge(args)
end
@@ -89,7 +90,13 @@ def load_defaults!
end
##
- # Check missing methods for deprecations
+ # Check missing methods for deprecated attribute accessors.
+ #
+ # If a value is set on an accessor that has been deprecated
+ # using #attr_deprecate, a warning will be issued and any
+ # :action (Proc) specified will be called with a reference to
+ # the class instance and the value set on the deprecated accessor.
+ # See #attr_deprecate and #log_deprecation_warning
#
# Note that OpenStruct (used for setting defaults) does not allow
# multiple arguments when assigning values for members.
@@ -99,6 +106,7 @@ def load_defaults!
# directly on the class' accessor, should not be supported.
# i.e. if an option will accept being set as an Array, then it
# should be explicitly set as such. e.g. option = [val1, val2]
+ #
def method_missing(name, *args)
deprecation = nil
if method = name.to_s.chomp!('=')
@@ -111,23 +119,7 @@ def method_missing(name, *args)
if deprecation
self.class.log_deprecation_warning(method, deprecation)
- if replacement = deprecation[:replacement]
- value =
- case deprecation[:value]
- when nil
- args[0]
- when Proc
- deprecation[:value].call(args[0])
- else
- deprecation[:value]
- end
- unless value.nil?
- Logger.warn(
- "#{ self.class }.#{ replacement } is being set to '#{ value }'"
- )
- send(:"#{ replacement }=", value)
- end
- end
+ deprecation[:action].call(self, args[0]) if deprecation[:action]
else
super
end
@@ -33,7 +33,8 @@ class MongoDB < Base
attr_accessor :mongodump_utility
attr_deprecate :utility_path, :version => '3.0.21',
- :replacement => :mongodump_utility
+ :message => 'Use MongoDB#mongodump_utility instead.',
+ :action => lambda {|klass, val| klass.mongodump_utility = val }
##
# Path to the mongo utility (optional)
@@ -34,7 +34,8 @@ class MySQL < Base
attr_accessor :mysqldump_utility
attr_deprecate :utility_path, :version => '3.0.21',
- :replacement => :mysqldump_utility
+ :message => 'Use MySQL#mysqldump_utility instead.',
+ :action => lambda {|klass, val| klass.mysqldump_utility = val }
##
# Creates a new instance of the MySQL adapter object
@@ -33,7 +33,8 @@ class PostgreSQL < Base
attr_accessor :pg_dump_utility
attr_deprecate :utility_path, :version => '3.0.21',
- :replacement => :pg_dump_utility
+ :message => 'Use PostgreSQL#pg_dump_utility instead.',
+ :action => lambda {|klass, val| klass.pg_dump_utility = val }
##
# Creates a new instance of the PostgreSQL adapter object
@@ -31,7 +31,8 @@ class Redis < Base
attr_accessor :redis_cli_utility
attr_deprecate :utility_path, :version => '3.0.21',
- :replacement => :redis_cli_utility
+ :message => 'Use Redis#redis_cli_utility instead.',
+ :action => lambda {|klass, val| klass.redis_cli_utility = val }
##
# Creates a new instance of the Redis database object
@@ -21,7 +21,8 @@ class Riak < Base
attr_accessor :riak_admin_utility
attr_deprecate :utility_path, :version => '3.0.21',
- :replacement => :riak_admin_utility
+ :message => 'Use Riak#riak_admin_utility instead.',
+ :action => lambda {|klass, val| klass.riak_admin_utility = val }
##
# Creates a new instance of the Riak adapter object
Oops, something went wrong.

0 comments on commit bcb78d8

Please sign in to comment.