class Utopia::Command::Environment

Set environment variables within the server deployment.

Public Class Methods

defaults(destination_root) click to toggle source
# 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

Public Instance Methods

call(root = parent.root) click to toggle source
# 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() click to toggle source
# File lib/utopia/command/environment.rb, line 46
def environment_name
        @options[:environment_name]
end
update_environment(root, name = self.environment_name) { |store, name, environment_path| ... } click to toggle source

Setup `config/environment.yaml` according to specified options.

# 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