Class: Utopia::Setup
- Inherits:
-
Object
- Object
- Utopia::Setup
- Defined in:
- lib/utopia/setup.rb
Overview
Used for setting up a Utopia web application, typically via config/environment.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#apply! ⇒ Object
Apply.
-
#config_root ⇒ Object
Resolve the application's configuration directory.
-
#development? ⇒ Boolean
Check whether the application is running in development.
-
#initialize(root, **options) ⇒ Setup
constructor
Initialize application setup for the given root.
-
#production? ⇒ Boolean
Check whether the application is running in production.
-
#secret_for(key) ⇒ Object
Fetch the configured secret for the given key.
-
#site_root ⇒ Object
Return the application root.
-
#staging? ⇒ Boolean
Check whether the application is running in staging.
-
#testing? ⇒ Boolean
Check whether the application is running in testing.
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
23 24 25 |
# File 'lib/utopia/setup.rb', line 23 def root @root end |
Instance Method Details
#apply! ⇒ Object
Apply.
80 81 82 83 84 85 86 |
# File 'lib/utopia/setup.rb', line 80 def apply! add_load_path("lib") apply_environment require_relative "../utopia" end |
#config_root ⇒ Object
Resolve the application's configuration directory.
27 28 29 |
# File 'lib/utopia/setup.rb', line 27 def config_root File.("config", @root) end |
#development? ⇒ Boolean
Check whether the application is running in development.
51 52 53 |
# File 'lib/utopia/setup.rb', line 51 def development? Variant.for(:utopia) == :development end |
#production? ⇒ Boolean
Check whether the application is running in production.
39 40 41 |
# File 'lib/utopia/setup.rb', line 39 def production? Variant.for(:utopia) == :production end |
#secret_for(key) ⇒ Object
Fetch the configured secret for the given key.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/utopia/setup.rb', line 64 def secret_for(key) secret = ENV["UTOPIA_#{key.upcase}_SECRET"] if secret.nil? || secret.empty? secret = SecureRandom.hex(32) Console.warn(self) do "Generating transient #{key} secret: #{secret.inspect}" end end return secret end |
#site_root ⇒ Object
Return the application root.
33 34 35 |
# File 'lib/utopia/setup.rb', line 33 def site_root @root end |
#staging? ⇒ Boolean
Check whether the application is running in staging.
45 46 47 |
# File 'lib/utopia/setup.rb', line 45 def staging? Variant.for(:utopia) == :staging end |
#testing? ⇒ Boolean
Check whether the application is running in testing.
57 58 59 |
# File 'lib/utopia/setup.rb', line 57 def testing? Variant.for(:utopia) == :testing end |