Sha256: f242f6ee775ad4f82c817da44cb529e1028b882a830b463623392535996a5a70

Contents?: true

Size: 850 Bytes

Versions: 1

Compression:

Stored size: 850 Bytes

Contents

require 'yaml'

module Dbcp
  class DatabaseYamlEnvironmentProvider
    def initialize(database_yaml_path)
      @database_yaml_path = database_yaml_path
    end

    # @return [Environment, nil]
    def find(environment_name)
      begin
        environment_hash = read_file[environment_name]
        if environment_hash
          build_environment environment_name, environment_hash
        else
          nil
        end
      rescue Errno::ENOENT
        return nil
      end
    end

   private

    def read_file
      YAML.load_file @database_yaml_path
    end

    def build_environment(environment_name, environment_hash)
      Environment.new({
        environment_name: environment_name,
        database:         Database.build(environment_hash),
        execution_host:   ExecutionHost.build(environment_hash)
      })
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dbcp-0.0.1 lib/dbcp/environment_providers/database_yaml_environment_provider.rb