Sha256: 0decba91baab12b75567f92976e0dd577064e1e9b8ebb95c65ac950d47e641f4

Contents?: true

Size: 899 Bytes

Versions: 8

Compression:

Stored size: 899 Bytes

Contents

require 'yaml'
require 'erb'

class SpecClient

  def self.load_config(file)
    YAML.load(ERB.new(File.read(file)).result)
  end

  def self.mysql(name)
    file = File.join(File.dirname(__FILE__), '..', 'config', 'connections', 'mysql', "#{name}.yml")
    config = self.load_config(file)
    db = config[:database]
    config.delete(:database)
    connection = ::Mysql2::Client.new(config)
    begin 
      connection.query("use `#{db}`")
    rescue Exception => e
      puts "#{e} => will create new databse #{db}"
    end
    connection
  end

  def self.elasticsearch(name)
    file = File.join(File.dirname(__FILE__), '..', 'config', 'connections', 'elasticsearch', "#{name}.yml")
    config = self.load_config(file)
    ::Elasticsearch::Client.new(config)
  end

  def self.csv(file)
    CSV.read(file, :headers => true, :converters => :all).map {|r| r = r.to_hash.symbolize_keys }
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
forklift_etl-1.1.0 spec/support/spec_client.rb
forklift_etl-1.0.19 spec/support/spec_client.rb
forklift_etl-1.0.18 spec/support/spec_client.rb
forklift_etl-1.0.17 spec/support/spec_client.rb
forklift_etl-1.0.16 spec/support/spec_client.rb
forklift_etl-1.0.15 spec/support/spec_client.rb
forklift_etl-1.0.14 spec/support/spec_client.rb
forklift_etl-1.0.12 spec/support/spec_client.rb