Sha256: ad590b28fcd70f5c807834c355ad9992ca5a80c9ef15fbf25c6a4a8974212540

Contents?: true

Size: 1.72 KB

Versions: 30

Compression:

Stored size: 1.72 KB

Contents

module AdapterHelper
  class Base
    class << self
      attr_accessor :adapter

      def load_connection_from_env(adapter)
        self.adapter = adapter
        unless ENV['cpk_adapters']
          puts error_msg_setup_helper
          exit
        end

        ActiveRecord::Base.configurations = YAML.load(ENV['cpk_adapters'])
        unless spec = ActiveRecord::Base.configurations[adapter]
          puts error_msg_adapter_helper
          exit
        end
        spec[:adapter] = adapter
        spec
      end
    
      def error_msg_setup_helper
        <<-EOS
Setup Helper:
  CPK now has a place for your individual testing configuration.
  That is, instead of hardcoding it in the Rakefile and test/connections files,
  there is now a local/database_connections.rb file that is NOT in the
  repository. Your personal DB information (username, password etc) can
  be stored here without making it difficult to submit patches etc.

Installation:
  i)   cp locals/database_connections.rb.sample locals/database_connections.rb
  ii)  For #{adapter} connection details see "Adapter Setup Helper" below.
  iii) Rerun this task
  
#{error_msg_adapter_helper}
  
Current ENV:
  #{ENV.inspect}
        EOS
      end
        
      def error_msg_adapter_helper
        <<-EOS
Adapter Setup Helper:
  To run #{adapter} tests, you need to setup your #{adapter} connections.
  In your local/database_connections.rb file, within the ENV['cpk_adapter'] hash, add:
      "#{adapter}" => { adapter settings }

  That is, it will look like:
    ENV['cpk_adapters'] = {
      "#{adapter}" => {
        :adapter  => "#{adapter}",
        :username => "root",
        :password => "root",
        # ...
      }
    }.to_yaml
        EOS
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 6 rubygems

Version Path
composite_primary_keys-1.0.3 lib/adapter_helper/base.rb
composite_primary_keys-2.2.1 lib/adapter_helper/base.rb
composite_primary_keys-2.2.0 lib/adapter_helper/base.rb
composite_primary_keys-1.1.0 lib/adapter_helper/base.rb
composite_primary_keys-1.0.8 lib/adapter_helper/base.rb
composite_primary_keys-1.0.7 lib/adapter_helper/base.rb
composite_primary_keys-1.0.6 lib/adapter_helper/base.rb
composite_primary_keys-1.0.5 lib/adapter_helper/base.rb
composite_primary_keys-1.0.4 lib/adapter_helper/base.rb
composite_primary_keys-2.2.2 lib/adapter_helper/base.rb