Class: Db::Clone::CmdBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/db/clone/cmd_builder.rb

Constant Summary collapse

VALID_DB_KEYS =
['host', 'port', 'username', 'database', 'password']
SUPPORTED_DBS =
[:mysql, :postgresql]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selections) ⇒ CmdBuilder

Returns a new instance of CmdBuilder.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
# File 'lib/db/clone/cmd_builder.rb', line 9

def initialize selections
  raise ArgumentError.new('Both source and destination must be set') unless selections[:src] && selections[:dest]
  raise ArgumentError.new('Source and destination databases must be of the same type') unless selections[:src]['adapter'] == selections[:dest]['adapter']
  SUPPORTED_DBS.each{|db| @db_type = db if selections[:src]['adapter'].include?(db.to_s)}
  raise ArgumentError.new("Unsupported database: #{selections[:src]['adapter']}") unless @db_type
  src_dest = selections.map{|k,v| [k,v.delete_if{|i,j| !VALID_DB_KEYS.include?(i)}]}.to_h
  @cmd = send "build_#{@db_type}_cmd", src_dest
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



7
8
9
# File 'lib/db/clone/cmd_builder.rb', line 7

def cmd
  @cmd
end