Sha256: 305944e9c8171b6f2ce529235bb6d130659b0b01c63237f07061bc35c8098d5d
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
# encoding: utf-8 module Backup module Configuration module Helpers ## # Finds all the object's getter methods and checks the global # configuration for these methods, if they respond then they will # assign the object's attribute(s) to that particular global configuration's attribute def load_defaults!(options = {}) c = self.class.name.split('::') configuration = Backup::Configuration.const_get(c[1]).const_get(c[2]) options[:except] ||= [] options[:only] ||= [] getter_methods.each do |attribute| if configuration.respond_to?(attribute) if options[:only].any? and options[:only].include?(attribute) self.send("#{attribute}=", configuration.send(attribute)) elsif options[:except].any? and !options[:except].include?(attribute) self.send("#{attribute}=", configuration.send(attribute)) elsif options[:only].empty? and options[:except].empty? self.send("#{attribute}=", configuration.send(attribute)) end end end end ## # Clears all the defaults that may have been set by the user def clear_defaults! setter_methods.each do |method| self.send(method, nil) end end ## # Returns an array of the setter methods (as String) def setter_methods methods.map do |method| method = method.to_s method if method =~ /^\w(\w|\d|\_)+\=$/ and method != 'taguri=' end.compact end ## # Returns an array of getter methods (as Array) def getter_methods methods.map do |method| method = method.to_s if method =~ /^\w(\w|\d|\_)+\=$/ and method != 'taguri=' method.sub('=','') end end.compact end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
backup-3.0.19 | lib/backup/configuration/helpers.rb |
backup-3.0.18 | lib/backup/configuration/helpers.rb |