Class: Connectator::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/connectator/factory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connectator_params) ⇒ Factory

Returns a new instance of Factory.



18
19
20
# File 'lib/connectator/factory.rb', line 18

def initialize(connectator_params)
  @connectator_params = connectator_params
end

Instance Attribute Details

#connectator_paramsObject (readonly)

Returns the value of attribute connectator_params.



16
17
18
# File 'lib/connectator/factory.rb', line 16

def connectator_params
  @connectator_params
end

Class Method Details

.build(connectator_params) ⇒ Object

connectator_params object must respond to:

  • kind (Oracle, Sql, Sybase, DB2)

  • server

  • instance

  • port

  • username

  • password



12
13
14
# File 'lib/connectator/factory.rb', line 12

def self.build(connectator_params)
  return self.new(connectator_params).connection
end

Instance Method Details

#connection(additional_params = {}) ⇒ Object



22
23
24
# File 'lib/connectator/factory.rb', line 22

def connection(additional_params = {})
  connection_class.new(extract_connectator_params.merge(additional_params))
end

#connection_classObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/connectator/factory.rb', line 26

def connection_class
  case connectator_symbol
  when :db2              then Connectator::DB2::Connection
  when :mysql            then Connectator::MySQL::Connection
  when :oracle           then Connectator::Oracle::Connection
  when :sql, :sql_server then Connectator::SQL::Connection
  when :sybase           then Connectator::Sybase::Connection
  else                        raise "Connectator class was not found"
  end
end

#extract_connectator_paramsObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/connectator/factory.rb', line 37

def extract_connectator_params
  {
   :server   => rescue_as_nil { connectator_params.server   },
   :instance => rescue_as_nil { connectator_params.instance },
   :database => rescue_as_nil { connectator_params.database },
   :port     => rescue_as_nil { connectator_params.port     },
   :option   => rescue_as_nil { connectator_params.option   },
   :username => rescue_as_nil { connectator_params.username },
   :password => rescue_as_nil { connectator_params.password }
  }
end