Class: Utopia::Bootstrap

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/setup.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_root, external_encoding: Encoding::UTF_8) ⇒ Bootstrap

Returns a new instance of Bootstrap.



23
24
25
26
27
# File 'lib/utopia/setup.rb', line 23

def initialize(config_root, external_encoding: Encoding::UTF_8)
	@config_root = config_root
	
	@external_encoding = external_encoding
end

Instance Method Details

#environment_pathObject



39
40
41
# File 'lib/utopia/setup.rb', line 39

def environment_path
	File.expand_path('environment.yaml', @config_root)
end

#setupObject



29
30
31
32
33
34
35
36
37
# File 'lib/utopia/setup.rb', line 29

def setup
	setup_encoding
	
	setup_environment
	
	setup_load_path
	
	require_relative '../utopia'
end

#setup_encodingObject

If you don’t specify these, it’s possible to have issues when encodings mismatch on the server.



44
45
46
47
48
49
50
# File 'lib/utopia/setup.rb', line 44

def setup_encoding
	# TODO: Deprecate and remove this setup - it should be the responsibility of the server to set this correctly.
	if @external_encoding and Encoding.default_external != @external_encoding
		warn "Updating Encoding.default_external from #{Encoding.default_external} to #{@external_encoding}"
		Encoding.default_external = @external_encoding
	end
end

#setup_environmentObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/utopia/setup.rb', line 52

def setup_environment
	if File.exist? environment_path
		require 'yaml'
		
		# Load the YAML environment file:
		environment = YAML.load_file(environment_path)
		
		# We update ENV but only when it's not already set to something:
		ENV.update(environment) do |name, old_value, new_value|
			old_value || new_value
		end
	end
end

#setup_load_pathObject



66
67
68
69
# File 'lib/utopia/setup.rb', line 66

def setup_load_path
	# Allow loading library code from lib directory:
	$LOAD_PATH << File.expand_path('../lib', @config_root)
end