Class: Mooncell::Environment Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mooncell/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.

Mooncell environment

Since:

  • 0.1.0

Constant Summary collapse

LOCK =

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.

Global lock

Since:

  • 0.1.0

Mutex.new
MOONCELL_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 Mooncell ENV Key

Since:

  • 0.1.0

'MOONCELL_ENV'
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 Mooncell environment

Since:

  • 0.1.0

'development'
TEST_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.

Mooncell test environment

Since:

  • 0.1.0

'test'
PRODUCTION_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.

Mooncell production environment

Since:

  • 0.1.0

'production'
APPS_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.

Since:

  • 0.1.0

'apps'
DOTENV_LOCAL_FILE =

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.

Since:

  • 0.1.0

'.env.local'
DOTENV_FILES =

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` files will be loaded

Since:

  • 0.1.0

[
  '.env.%<environment>s.local',
  DOTENV_LOCAL_FILE,
  '.env.%<environment>s',
  '.env'
].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.

Since:

  • 0.1.0

{
  'development' => true
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ 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 Mooncell Environment

Since:

  • 0.1.0



69
70
71
72
73
# File 'lib/mooncell/environment.rb', line 69

def initialize(options = {})
  opts = options.to_h.dup
  @env = Mooncell::Env.new(env: opts.delete(:env) || ENV)
  LOCK.synchronize { load_env_vars! }
end

Instance Method Details

#apps_pathObject

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.

Since:

  • 0.1.0



101
102
103
# File 'lib/mooncell/environment.rb', line 101

def apps_path
  root.join(APPS_PATH)
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 current environment

Returns:

  • (TrueClass, FalseClass)

    the result of check

Since:

  • 0.1.0



132
133
134
# File 'lib/mooncell/environment.rb', line 132

def code_reloading?
  !!CODE_RELOADING[environment] # rubocop:disable Style/DoubleNegation
end

#configPathname Also known as: project_config

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.

Project environment configuration path

Returns:

  • (Pathname)

    path to application

Since:

  • 0.1.0



111
112
113
# File 'lib/mooncell/environment.rb', line 111

def config
  root.join('config', 'environment.rb')
end

#environmentString

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

Returns:

  • (String)

    the current environment

See Also:

  • DEFAULT_ENF

Since:

  • 0.1.0



95
96
97
# File 'lib/mooncell/environment.rb', line 95

def environment
  @environment ||= env[MOONCELL_ENV] || DEFAULT_ENV
end

#require_project_environmentObject

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.

Load project environment configuration

Since:

  • 0.1.0



122
123
124
# File 'lib/mooncell/environment.rb', line 122

def require_project_environment
  require project_config.to_s
end

#rootPathname

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

Returns:

  • (Pathname)

    application’s root

Since:

  • 0.1.0



81
82
83
84
85
# File 'lib/mooncell/environment.rb', line 81

def root
  @root ||= Bundler.root
rescue Bundler::GemfileNotFound
  @root = Pathname.new(Dir.pwd)
end