Class: Lotus::Environment Private
- Inherits:
-
Object
- Object
- Lotus::Environment
- Defined in:
- lib/lotus/environment.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Define and expose information about the Lotus environment.
Constant Summary collapse
- RACK_ENV =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Standard Rack ENV key
'RACK_ENV'.freeze
- LOTUS_ENV =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Standard Lotus ENV key
'LOTUS_ENV'.freeze
- DEFAULT_ENV =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default Lotus environment
'development'.freeze
- DEFAULT_DOTENV =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default ‘.env` file name
'.env'.freeze
- DEFAULT_DOTENV_ENV =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default ‘.env` per environment file name
'.env.%s'.freeze
- DEFAULT_CONFIG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default configuration directory under application root
'config'.freeze
- LOTUS_HOST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Standard Lotus host ENV key
'LOTUS_HOST'.freeze
- DEFAULT_HOST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default HTTP host
'localhost'.freeze
- LISTEN_ALL_HOST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default IP address listen
'0.0.0.0'.freeze
- LOTUS_PORT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Standard Lotus port ENV key
'LOTUS_PORT'.freeze
- DEFAULT_PORT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default Lotus HTTP port
2300
- DEFAULT_RACKUP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default Rack configuration file
'config.ru'.freeze
- DEFAULT_ENVIRONMENT_CONFIG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default environment configuration file
'environment'.freeze
- CODE_RELOADING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Code reloading per environment
{ 'development' => true }.freeze
- CONTAINER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'container'.freeze
- CONTAINER_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'apps'.freeze
- APPLICATION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'app'.freeze
- APPLICATION_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'app'.freeze
Instance Method Summary collapse
- #apps_path ⇒ Object private
- #architecture ⇒ Object private
-
#bundler_groups ⇒ Array
private
A set of Bundler groups.
-
#code_reloading? ⇒ TrueClass, FalseClass
private
Determine if activate code reloading for the current environment while running the server.
-
#config ⇒ Pathname
private
Application’s config directory.
- #container? ⇒ Boolean private
-
#env_config ⇒ Pathname
private
Path to environment configuration file.
-
#environment ⇒ String
private
The current environment.
- #environment?(*names) ⇒ Boolean private
-
#host ⇒ String
private
The HTTP host name.
-
#initialize(options = {}) ⇒ Lotus::Environment
constructor
private
Initialize a Lotus environment.
-
#port ⇒ Integer
private
The HTTP port.
-
#rackup ⇒ Pathname
private
Path to the Rack configuration file.
-
#require_application_environment ⇒ Object
private
Require application environment.
-
#root ⇒ Pathname
private
Application’s root.
-
#to_options ⇒ Lotus::Utils::Hash
private
Serialize the most relevant settings into a Hash.
Constructor Details
#initialize(options = {}) ⇒ Lotus::Environment
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a Lotus environment
It accepts an optional set of configurations from the CLI commands. Those settings override the defaults defined by this object.
When initialized, it sets standard ‘ENV` variables for Rack and Lotus, such as `RACK_ENV` and `LOTUS_ENV`.
It also evaluates configuration from ‘.env` and `.env.<environment>` located under the config directory. All the settings in those files will be exported as `ENV` variables.
The format of those ‘.env` files is compatible with `dotenv` and `foreman` gems.
175 176 177 178 179 180 |
# File 'lib/lotus/environment.rb', line 175 def initialize( = {}) @options = Lotus::Lotusrc.new(root, ).read @options.merge! Utils::Hash.new().symbolize! @mutex = Mutex.new @mutex.synchronize { set_env_vars! } end |
Instance Method Details
#apps_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
390 391 392 393 394 395 396 397 |
# File 'lib/lotus/environment.rb', line 390 def apps_path @options.fetch(:path) { case architecture when CONTAINER then CONTAINER_PATH when APPLICATION then APPLICATION_PATH end } end |
#architecture ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
375 376 377 378 379 380 |
# File 'lib/lotus/environment.rb', line 375 def architecture @options.fetch(:architecture) { puts "Cannot recognize Lotus architecture, please check `.lotusrc'" exit 1 } end |
#bundler_groups ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A set of Bundler groups
215 216 217 |
# File 'lib/lotus/environment.rb', line 215 def bundler_groups [environment] end |
#code_reloading? ⇒ TrueClass, FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine if activate code reloading for the current environment while running the server.
In order to decide the value, it looks up the following sources:
* CLI option `code_reloading`
If those are missing it falls back to the following defaults:
* true for development
* false for all the other environments
363 364 365 366 367 368 369 370 371 |
# File 'lib/lotus/environment.rb', line 363 def code_reloading? # JRuby doesn't implement fork that's why shotgun cannot be used. if Utils.jruby? puts "JRuby doesn't support code reloading." false else @options.fetch(:code_reloading) { !!CODE_RELOADING[environment] } end end |
#config ⇒ Pathname
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Application’s config directory
It’s the application where all the configurations are stored.
In order to decide the value, it looks up the following sources:
* CLI option `config`
If those are missing it falls back to the default one: ‘“config/”`.
When a relative path is given via CLI option, it assumes to be located under application’s root. If absolute path, it will be used as it is.
250 251 252 |
# File 'lib/lotus/environment.rb', line 250 def config @config ||= root.join(@options.fetch(:config) { DEFAULT_CONFIG }) end |
#container? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
384 385 386 |
# File 'lib/lotus/environment.rb', line 384 def container? architecture == CONTAINER end |
#env_config ⇒ Pathname
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Path to environment configuration file.
In order to decide the value, it looks up the following sources:
* CLI option `environment`
If those are missing it falls back to the default one: ‘“config/environment.rb”`.
When a relative path is given via CLI option, it assumes to be located under application’s root. If absolute path, it will be used as it is.
331 332 333 |
# File 'lib/lotus/environment.rb', line 331 def env_config root.join(@options.fetch(:environment) { config.join(DEFAULT_ENVIRONMENT_CONFIG) }) end |
#environment ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The current environment
In order to decide the value, it looks up to the following ‘ENV` vars:
* LOTUS_ENV
* RACK_ENV
If those are missing it falls back to the defalt one: ‘“development”`.
196 197 198 |
# File 'lib/lotus/environment.rb', line 196 def environment @environment ||= ENV[LOTUS_ENV] || ENV[RACK_ENV] || DEFAULT_ENV end |
#environment?(*names) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
203 204 205 |
# File 'lib/lotus/environment.rb', line 203 def environment?(*names) names.map(&:to_s).include?(environment) end |
#host ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The HTTP host name
In order to decide the value, it looks up the following sources:
* CLI option `host`
* LOTUS_HOST ENV var
If those are missing it falls back to the following defaults:
* `"localhost"` for development
* `"0.0.0.0"` for all the other environments
272 273 274 275 276 |
# File 'lib/lotus/environment.rb', line 272 def host @host ||= @options.fetch(:host) { ENV[LOTUS_HOST] || default_host } end |
#port ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The HTTP port
In order to decide the value, it looks up the following sources:
* CLI option `port`
* LOTUS_PORT ENV var
If those are missing it falls back to the default one: ‘2300`.
292 293 294 |
# File 'lib/lotus/environment.rb', line 292 def port @port ||= @options.fetch(:port) { ENV[LOTUS_PORT] || DEFAULT_PORT }.to_i end |
#rackup ⇒ Pathname
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Path to the Rack configuration file
In order to decide the value, it looks up the following sources:
* CLI option `rackup`
If those are missing it falls back to the default one: ‘“config.ru”`.
When a relative path is given via CLI option, it assumes to be located under application’s root. If absolute path, it will be used as it is.
310 311 312 |
# File 'lib/lotus/environment.rb', line 310 def rackup root.join(@options.fetch(:rackup) { DEFAULT_RACKUP }) end |
#require_application_environment ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Require application environment
Eg require "config/environment"
.
341 342 343 |
# File 'lib/lotus/environment.rb', line 341 def require_application_environment require env_config.to_s end |
#root ⇒ Pathname
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Application’s root
It defaults to the current working directory. Lotus assumes that all the commands are executed from there.
227 228 229 |
# File 'lib/lotus/environment.rb', line 227 def root @root ||= Pathname.new(Dir.pwd) end |
#to_options ⇒ Lotus::Utils::Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serialize the most relevant settings into a Hash
405 406 407 408 409 410 411 412 413 414 |
# File 'lib/lotus/environment.rb', line 405 def @options.merge( environment: environment, env_config: env_config, apps_path: apps_path, rackup: rackup, host: host, port: port ) end |