Class: Utopia::Bootstrap
- Inherits:
-
Object
- Object
- Utopia::Bootstrap
- Defined in:
- lib/utopia/setup.rb
Instance Method Summary collapse
- #environment_path ⇒ Object
-
#initialize(config_root, external_encoding: Encoding::UTF_8) ⇒ Bootstrap
constructor
A new instance of Bootstrap.
- #setup ⇒ Object
-
#setup_encoding ⇒ Object
If you don’t specify these, it’s possible to have issues when encodings mismatch on the server.
- #setup_environment ⇒ Object
- #setup_load_path ⇒ Object
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_path ⇒ Object
39 40 41 |
# File 'lib/utopia/setup.rb', line 39 def environment_path File.('environment.yaml', @config_root) end |
#setup ⇒ Object
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_encoding ⇒ Object
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_environment ⇒ Object
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_path ⇒ Object
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.('../lib', @config_root) end |