Sha256: d513d8652a20e02844ada8c68169e2041bbc4d825a429e8fa303dbc648d55ec9

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module BackupJenkins
  class Config
    attr_reader :s3

    def initialize
      @config = config_file
    end

    def method_missing(meth, *args, &block)
      return config[meth.to_s] if config.has_key?(meth.to_s)
      super
    end

    def respond_to?(meth)
      config.has_key?(meth.to_s) || super
    end

    def base_file_name
      "#{backup["file_name_base"]}_#{hostname}"
    end

    def hostname
      %x{hostname -s}.chomp
    end

    private

    attr_reader :config

    def config_file
      YAML.load_file(config_file_path)
    rescue Errno::ENOENT
      STDERR.puts "Please create a config file in #{config_file_path}"
      STDERR.puts "\nIt should look like:\n\n#{config_file_example}"

      exit 1
    end

    def config_file_path
      "#{ENV['HOME']}/.config/backup_jenkins/config.yml"
    end

    def config_file_example
      File.read(config_file_example_path)
    end

    def config_file_example_path
      File.expand_path('../../../config/config-example.yml', __FILE__)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
backup_jenkins-0.0.5 lib/backup_jenkins/config.rb
backup_jenkins-0.0.4 lib/backup_jenkins/config.rb
backup_jenkins-0.0.3 lib/backup_jenkins/config.rb