Class: Utopia::Command::Environment
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Utopia::Command::Environment
- Defined in:
- lib/utopia/command/environment.rb
Overview
Set environment variables within the server deployment.
Class Method Summary collapse
Instance Method Summary collapse
- #call(root = parent.root) ⇒ Object
- #environment_name ⇒ Object
-
#update_environment(root, name = self.environment_name) ⇒ Object
Setup ‘config/environment.yaml` according to specified options.
Class Method Details
.defaults(destination_root) ⇒ Object
40 41 42 43 44 |
# File 'lib/utopia/command/environment.rb', line 40 def self.defaults(destination_root) # Set some useful defaults for the environment. self["--environment-name", "testing", "--defaults"].call(destination_root) self["--environment-name", "development", "--defaults"].call(destination_root) end |
Instance Method Details
#call(root = parent.root) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/utopia/command/environment.rb', line 62 def call(root = parent.root) update_environment(root) do |store, name, path| if @options[:defaults] # Set some useful defaults for the environment. store['UTOPIA_SESSION_SECRET'] ||= SecureRandom.hex(40) end 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 Console.logger.debug(self) do |buffer| buffer.puts "Environment #{name} (#{path}):" store.roots.each do |key| value = store[key] buffer.puts "#{key}=#{value.inspect}" end end end end |
#environment_name ⇒ Object
46 47 48 |
# File 'lib/utopia/command/environment.rb', line 46 def environment_name @options[:environment_name] end |
#update_environment(root, name = self.environment_name) ⇒ Object
Setup ‘config/environment.yaml` according to specified options.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/utopia/command/environment.rb', line 51 def update_environment(root, name = self.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, name, environment_path end end |