Class: Brut::Framework::ProjectEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/brut/framework/project_environment.rb

Overview

Manages the interpretation of dev/test/prod. The canonical instance is available via Brut.container.project_env. Generally, you should avoid basing logic on this, or at least contain the conditional behavior to the configuration values. But, you do you.

Instance Method Summary collapse

Constructor Details

#initialize(string_value) ⇒ ProjectEnvironment

Create the project environment based on the string

Parameters:

  • string_value (String)

    value from e.g. ENV["RACK_ENV"] to use to set the environment

Raises:

  • (ArgumentError)

    if the string does not map to a known environment.



9
10
11
12
13
14
15
16
17
# File 'lib/brut/framework/project_environment.rb', line 9

def initialize(string_value)
  @value = case string_value
  when "development" then "development"
  when "test"        then "test"
  when "production"  then "production"
  else
    raise ArgumentError.new("'#{string_value}' is not a valid project environment")
  end
end

Instance Method Details

#development?true|false

Returns true is this is development.

Returns:

  • (true|false)

    true is this is development



20
21
# File 'lib/brut/framework/project_environment.rb', line 20

def development? = @value == "development"
# @return [true|false] true is this is test

#production?true|false

Returns true is this is production.

Returns:

  • (true|false)

    true is this is production



24
# File 'lib/brut/framework/project_environment.rb', line 24

def production?  = @value == "production"

#staging?Boolean

Returns:

  • (Boolean)


26
# File 'lib/brut/framework/project_environment.rb', line 26

def staging? = raise "Staging is a lie, please consider feature flags or literally any other way to manage in-development features of your app. I promise you, you will regret ever having to do anything with a staging server"

#test?true|false

Returns true is this is test.

Returns:

  • (true|false)

    true is this is test



22
23
# File 'lib/brut/framework/project_environment.rb', line 22

def test?        = @value == "test"
# @return [true|false] true is this is production

#to_sString

Returns the string value (which should be suitable for the constructor).

Returns:

  • (String)

    the string value (which should be suitable for the constructor)



29
# File 'lib/brut/framework/project_environment.rb', line 29

def to_s = @value