Sha256: c3ae8d8eb3685a27822b0e199e6f2e7d5a03f0283279cc87afbad413065c2158

Contents?: true

Size: 1.48 KB

Versions: 22

Compression:

Stored size: 1.48 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!
        c             = self.class.name.split('::')
        configuration = Backup::Configuration.const_get(c[1]).const_get(c[2])

        getter_methods.each do |attribute|
          if configuration.respond_to?(attribute)
            unless configuration.send(attribute).nil?
              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

22 entries across 22 versions & 3 rubygems

Version Path
backup-3.0.0.build.0 lib/backup/configuration/helpers.rb
backup-3.0.0 lib/backup/configuration/helpers.rb