Class: Utopia::Command::Environment

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/utopia/command/environment.rb

Overview

Set environment variables within the server deployment.

Instance Method Summary collapse

Instance Method Details

#invoke(parent) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/utopia/command/environment.rb', line 48

def invoke(parent)
  destination_root = parent.root
  
  update_environment(destination_root) do |store|
    variables.each do |variable|
      key, value = variable.split('=', 2)
      
      if value
        puts "ENV[#{key.inspect}] will default to #{value.inspect} unless otherwise specified."
        store[key] = value
      else
        puts "ENV[#{key.inspect}] will be unset unless otherwise specified."
        store.delete(key)
      end
    end
    
    store.roots.each do |key|
      value = store[key]
      
      puts "#{Rainbow(key).blue}: #{Rainbow(value.inspect).green}"
    end
  end
end

#update_environment(root, name = @options[:environment_name]) ⇒ Object

Setup config/environment.yaml according to specified options.



37
38
39
40
41
42
43
44
45
46
# File 'lib/utopia/command/environment.rb', line 37

def update_environment(root, name = @options[:environment_name])
  environment_path = File.join(root, "config", "#{name}.yaml")
  FileUtils.mkpath File.dirname(environment_path)
  
  store = YAML::Store.new(environment_path)
  
  store.transaction do
    yield store
  end
end