Class: Utopia::Bootstrap
- Inherits:
-
Object
- Object
- Utopia::Bootstrap
- Defined in:
- lib/utopia/setup.rb
Overview
Used for setting up a Utopia web application, typically via config/environment.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.
24 25 26 27 28 |
# File 'lib/utopia/setup.rb', line 24 def initialize(config_root, external_encoding: Encoding::UTF_8) @config_root = config_root @external_encoding = external_encoding end |
Instance Method Details
#environment_path ⇒ Object
40 41 42 |
# File 'lib/utopia/setup.rb', line 40 def environment_path File.('environment.yaml', @config_root) end |
#setup ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/utopia/setup.rb', line 30 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.
45 46 47 48 49 50 51 |
# File 'lib/utopia/setup.rb', line 45 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}" if $VERBOSE Encoding.default_external = @external_encoding end end |
#setup_environment ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/utopia/setup.rb', line 53 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
67 68 69 70 |
# File 'lib/utopia/setup.rb', line 67 def setup_load_path # Allow loading library code from lib directory: $LOAD_PATH << File.('../lib', @config_root) end |