Class: KTools::Tools::Swap
- Inherits:
-
Object
- Object
- KTools::Tools::Swap
- Defined in:
- lib/ktools/tools/swap.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Swap
constructor
A new instance of Swap.
- #start ⇒ Object
Constructor Details
#initialize(args) ⇒ Swap
Returns a new instance of Swap.
8 9 10 11 12 |
# File 'lib/ktools/tools/swap.rb', line 8 def initialize(args) @subject = args[0] @kube_path = KTools.configuration.kube_path @cfg = KTools::KDB.read end |
Class Method Details
.start(args) ⇒ Object
4 5 6 |
# File 'lib/ktools/tools/swap.rb', line 4 def self.start(args) self.new(args).start end |
Instance Method Details
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ktools/tools/swap.rb', line 14 def start unless @subject files = Dir["#{@kube_path}/*.yml", "#{@kube_path}/*.yaml"] files.each do |file| name = File.basename(file).chomp(".yml").chomp(".yaml") if name == @cfg["cluster"] puts "-> #{name}".colorize(:yellow) else puts "- #{name}" end end else c_file = "#{@kube_path}/config" File.delete(c_file) if File.exist?(c_file) subject_file = check_subject_file do_fail unless subject_file FileUtils.cp(subject_file, c_file) KTools::KDB.update(@cfg, {"cluster" => @subject}) puts "Swapped to #{@subject}." end end |