Method: Merb.merge_env

Defined in:
lib/merb-core.rb

.merge_env(env, use_db = false) ⇒ Object

Merge environment settings

This can allow you to have a “localdev” environment that runs like your “development”.

OR

A “staging” environment that runs identical to your “production” environment.

Examples

From any environment config file (ie, development.rb, custom.rb, localdev.rb, etc).

staging.rb:
  Merb.merge_env "production"         # We want to use all the settings production uses
  Merb::Config.use do |c|
    c[:log_level]         = "debug"   # except we want debug log level
    c[:log_stream]        = @some_io  # and log to this IO handle
    c[:exception_details] = true      # and we want to see exception details
  end

Parameters

env<~String>

Environment to run like

use_db<~Boolean>

Should Merb use the merged environments DB connection

Defaults to +false+

:api: public



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/merb-core.rb', line 103

def merge_env(env,use_db=false)
  if Merb.environment_info.nil?
    Merb.environment_info = {
      :real_env => Merb.environment,
      :merged_envs => [],
      :db_env => Merb.environment
    }
  end
  
  #Only load if it hasn't been loaded
  unless Merb.environment_info[:merged_envs].member? env
    Merb.environment_info[:merged_envs] << env
    
    env_file = Merb.dir_for(:config) / "environments" / ("#{env}.rb")
    if File.exists?(env_file)
      load(env_file)
    else
      Merb.logger.warn! "Environment file does not exist! #{env_file}"
    end
  end
  
  # Mark specific environment to load when ORM loads,
  # if multiple environments are loaded, the last one
  # with use_db as TRUE will be loaded
  if use_db
    Merb.environment_info[:db_env] = env
  end
end