Class: Switcher

Inherits:
Object
  • Object
show all
Defined in:
lib/env_switch/switcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(env_filename) ⇒ Switcher

Returns a new instance of Switcher.



2
3
4
# File 'lib/env_switch/switcher.rb', line 2

def initialize(env_filename)
  @env_filename = env_filename
end

Instance Method Details

#switchObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/env_switch/switcher.rb', line 6

def switch
  files = Dir.glob("*.env")

  result = files.select { |f| f == "#{@env_filename}.env" }

  if !result.empty?
    FileUtils.cp(result.first, '.env')
    puts "Copied #{result.first} to .env"
  else
    puts "No env found for #{@env_filename}"
  end

end