Class: Db::Clone::CmdBuilder
- Inherits:
-
Object
- Object
- Db::Clone::CmdBuilder
- 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
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
Instance Method Summary collapse
-
#initialize(selections) ⇒ CmdBuilder
constructor
A new instance of CmdBuilder.
Constructor Details
#initialize(selections) ⇒ CmdBuilder
Returns a new instance of CmdBuilder.
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
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
7 8 9 |
# File 'lib/db/clone/cmd_builder.rb', line 7 def cmd @cmd end |