Class: Guignol::Commands::Clone
- Inherits:
-
Object
- Object
- Guignol::Commands::Clone
- Defined in:
- lib/guignol/commands/clone.rb
Instance Method Summary collapse
-
#initialize(source_name, target_name) ⇒ Clone
constructor
A new instance of Clone.
- #run ⇒ Object
Constructor Details
#initialize(source_name, target_name) ⇒ Clone
Returns a new instance of Clone.
22 23 24 25 26 27 28 29 30 |
# File 'lib/guignol/commands/clone.rb', line 22 def initialize(source_name, target_name) @source_name = source_name @target_name = target_name @source_config = Guignol.configuration[source_name] unless @source_config raise Thor::Error.new "machine '#{source_name}' is unknown" end end |
Instance Method Details
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/guignol/commands/clone.rb', line 33 def run new_config = @source_config.map_to_hash(:deep => true) do |key,value| value = value.gsub(/#{@source_name}/, @target_name) if value.kind_of?(String) key = key.gsub( /#{@source_name}/, @target_name) if key.kind_of?(String) case key when :uuid [key, UUIDTools::UUID.random_create.to_s.upcase] else [key, value] end end $stdout.puts({@target_name => new_config}.to_yaml) end |