lib/hanami/environment.rb in hanami-1.0.0 vs lib/hanami/environment.rb in hanami-1.1.0.beta1
- old
+ new
@@ -108,26 +108,14 @@
# @api private
CODE_RELOADING = { 'development' => true }.freeze
# @since 0.4.0
# @api private
- CONTAINER = 'container'.freeze
+ APPS_PATH = 'apps'.freeze
# @since 0.4.0
# @api private
- CONTAINER_PATH = 'apps'.freeze
-
- # @since 0.4.0
- # @api private
- APPLICATION = 'app'.freeze
-
- # @since 0.4.0
- # @api private
- APPLICATION_PATH = 'app'.freeze
-
- # @since 0.4.0
- # @api private
SERVE_STATIC_ASSETS = 'SERVE_STATIC_ASSETS'.freeze
# @since 0.4.0
# @api private
SERVE_STATIC_ASSETS_ENABLED = 'true'.freeze
@@ -138,17 +126,22 @@
# Those settings override the defaults defined by this object.
#
# When initialized, it sets standard `ENV` variables for Rack and Hanami,
# such as `RACK_ENV` and `HANAMI_ENV`.
#
- # It also evaluates configuration from `.env` and `.env.<environment>`
+ # It evaluates configuration ONLY from `.env.<environment>` file
# 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.
+ # Master .env file is ignored to suggest clear separation of environment
+ # configurations and discourage putting sensitive information into source
+ # control.
#
+ # The format of those `.env.<environment>` files follows UNIX and UNIX-like
+ # operating system environment variable declaration format and compatible
+ # with `dotenv` and `foreman` gems.
+ #
# @param options [Hash] override default options for various environment
# attributes
#
# @return [Hanami::Environment] the environment
#
@@ -162,14 +155,14 @@
# @example Define ENV variables from .env
#
# # % tree .
# # .
# # # ...
- # # ├── .env
+ # # ├── .env.test
# # └── .env.development
#
- # # % cat .env
+ # # % cat .env.test
# # FOO="bar"
# # XYZ="yes"
#
# # % cat .env.development
# # FOO="ok"
@@ -186,26 +179,23 @@
# ENV['HANAMI_HOST'] # => "localhost"
# ENV['HANAMI_PORT'] # => "2300"
#
# # User defined ENV vars
# ENV['FOO'] # => "ok"
- # ENV['XYZ'] # => "yes"
+ # ENV['XYZ'] # => nil
#
- # # Hanami::Environment evaluates `.env` first as master configuration.
- # # Then it evaluates `.env.development` because the current environment
- # # is "development". The settings defined in this last file override
- # # the one defined in the parent (eg `FOO` is overwritten). All the
- # # other settings (eg `XYZ`) will be left untouched.
- # # Variables declared on `.env` and `.env.development` will not override
+ # # Hanami::Environment evaluates `.env.development` because the current
+ # # environment is "development".
+ # # Variables declared on `.env.development` will not override
# # any variable declared on the shell when calling a `hanami` command.
# # Eg. In `FOO="not ok" bundle exec hanami c` `FOO` will not be overwritten
# # to `"ok"`.
def initialize(options = {})
opts = options.to_h.dup
@env = Hanami::Env.new(env: opts.delete(:env) || ENV)
@options = Hanami::Hanamirc.new(root).options
- @options.merge! Utils::Hash.new(opts.clone).symbolize!
+ @options.merge! Utils::Hash.symbolize(opts.clone)
LOCK.synchronize { set_env_vars! }
end
# The current environment
#
@@ -387,11 +377,11 @@
# @since 0.1.0
# @api private
#
# @see Hanami::Environment::DEFAULT_ENVIRONMENT_CONFIG
def env_config
- root.join(@options.fetch(:environment) { config.join(DEFAULT_ENVIRONMENT_CONFIG) })
+ root.join("config", "environment.rb")
end
alias project_environment_configuration env_config
# Require application environment
@@ -428,25 +418,10 @@
# @see Hanami::Environment::CODE_RELOADING
def code_reloading?
@options.fetch(:code_reloading) { !!CODE_RELOADING[environment] }
end
- # @since 0.4.0
- # @api private
- def architecture
- @options.fetch(:architecture) do
- puts "Cannot recognize Hanami architecture, please check `.hanamirc'"
- exit 1
- end
- end
-
- # @since 0.4.0
- # @api private
- def container?
- architecture == CONTAINER
- end
-
# @since 0.6.0
# @api private
def serve_static_assets?
SERVE_STATIC_ASSETS_ENABLED == env[SERVE_STATIC_ASSETS]
end
@@ -466,20 +441,15 @@
end
# @since 0.4.0
# @api private
def apps_path
- @options.fetch(:path) {
- case architecture
- when CONTAINER then CONTAINER_PATH
- when APPLICATION then APPLICATION_PATH
- end
- }
+ @options.fetch(:path, APPS_PATH)
end
# Serialize the most relevant settings into a Hash
#
- # @return [Hanami::Utils::Hash]
+ # @return [::Hash]
#
# @since 0.1.0
# @api private
def to_options
@options.merge(