Module: Squixtures::HelperFactory

Defined in:
lib/squixtures/helper_factory.rb

Class Method Summary collapse

Class Method Details

.create_helper(settings) ⇒ Object

This method fetches an appropriate database helper instance based on the database connection details provided. The method will raise an exception if an unrecognised database type is encountered.

Parameters

settings

A Hash of the database connection settings.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/squixtures/helper_factory.rb', line 12

def self.create_helper(settings)
   adapter = settings['adapter']
   helper  = nil
   case adapter
      when 'postgresql', 'postgres'
         helper = PostgresHelper.new

      when 'sqlite3'
         helper = SQLite3Helper.new
   end

   if helper.nil?
      raise SquixtureError.new("Unrecognised database adapter '#{adapter}' encountered.")
   end
   helper
end