Sha256: eb8c1303757a47b4d3c1208288835df8aa08f048ddb45de86ae11d2b3268cd0c

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'yaml'
require 'erb'

module SimpleProvision
  class Configuration
    MissingServerType = Class.new(StandardError)
    MissingServerConfiguration = Class.new(StandardError)

    attr_reader :options
    attr_reader :profile

    def initialize(profile)
      @profile = profile

      read_and_parse_server_options
    end

    private

    def default_options
      begin
        YAML.load(ERB.new(File.read(default_file)).result)
      rescue Errno::ENOENT
        {}
      end
    end

    def server_options
      begin
        YAML.load(ERB.new(File.read(server_file)).result)
      rescue Errno::ENOENT
        raise MissingServerConfiguration, "Please create a configuration file at '#{server_file}'"
      end
    end

    def default_file
      "provision/servers/default.yml"
    end

    def server_file
      "provision/servers/#{profile}.yml"
    end

    def read_and_parse_server_options
      options_string_hash = default_options.merge(server_options)
      @options = Hash[options_string_hash.map{ |(k,v)| [k.to_sym, v] }]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_provision-0.99.13 lib/simple_provision/configuration.rb