Sha256: 4825b2fb4c06c9df8941fc5b89c04b9e6e2d66b624c95b9d31aa2fabda11f98e

Contents?: true

Size: 1.84 KB

Versions: 10

Compression:

Stored size: 1.84 KB

Contents

module SimpleDeploy
  class Config

    attr_accessor :config, :logger

    def initialize(args = {})
      self.config = args.fetch(:config) { load_config_file }
      self.logger = args[:logger] ||= SimpleDeployLogger.new
    end

    def artifacts
      ['chef_repo', 'cookbooks', 'app']
    end

    def artifact_deploy_variable(artifact)
      name_to_variable_map = { 'chef_repo' => 'CHEF_REPO_URL',
                               'app'       => 'APP_URL',
                               'cookbooks' => 'COOKBOOKS_URL' }
      name_to_variable_map[artifact]
    end

    def artifact_cloud_formation_url(artifact)
      name_to_url_map = { 'chef_repo' => 'ChefRepoURL',
                          'app'       => 'AppArtifactURL',
                          'cookbooks' => 'CookbooksURL' }
      name_to_url_map[artifact]
    end

    def deploy_script
      '/opt/intu/admin/bin/configure.sh'
    end

    def environments
      config['environments']
    end

    def environment(name)
      raise "Environment not found" unless environments.include? name
      environments[name]
    end

    def notifications
      config['notifications']
    end

    def region(name)
      environment(name)['region']
    end

    private

    def load_config_file
      begin
        YAML::load( File.open( config_file ) )
      rescue Errno::ENOENT
        raise "#{config_file} not found"
      rescue Psych::SyntaxError => e
        raise "#{config_file} is corrupt"
      end
    end

    def env_home
      env.load 'HOME'
    end

    def env_user
      env.load 'USER'
    end

    def config_file
      env_config_file || default_config_file
    end

    def env_config_file
      env.load 'SIMPLE_DEPLOY_CONFIG_FILE'
    end

    def default_config_file
      "#{env.load 'HOME'}/.simple_deploy.yml"
    end

    def env
      @env ||= SimpleDeploy::Env.new
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
simple_deploy-0.7.2.beta.1 lib/simple_deploy/config.rb
simple_deploy-0.7.1 lib/simple_deploy/config.rb
simple_deploy-0.7.0 lib/simple_deploy/config.rb
simple_deploy-0.6.7 lib/simple_deploy/config.rb
simple_deploy-0.6.6 lib/simple_deploy/config.rb
simple_deploy-0.6.5 lib/simple_deploy/config.rb
simple_deploy-0.6.4 lib/simple_deploy/config.rb
simple_deploy-0.6.3 lib/simple_deploy/config.rb
simple_deploy-0.6.2 lib/simple_deploy/config.rb
simple_deploy-0.6.1 lib/simple_deploy/config.rb