Class: AdapterHelper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/adapter_helper/base.rb

Direct Known Subclasses

MySQL, Oracle, Postgresql, Sqlite3

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.adapterObject

Returns the value of attribute adapter.



4
5
6
# File 'lib/adapter_helper/base.rb', line 4

def adapter
  @adapter
end

Class Method Details

.error_msg_adapter_helperObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/adapter_helper/base.rb', line 43

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

.error_msg_setup_helperObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/adapter_helper/base.rb', line 22

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

.load_connection_from_env(adapter) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/adapter_helper/base.rb', line 6

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