Module: Gaudi::Configuration

Defined in:
lib/gaudi/helpers/configuration.rb

Defined Under Namespace

Modules: BuildModules, EnvironmentOptions, SystemModules Classes: BuildConfiguration, Loader, PlatformConfiguration, SystemConfiguration

Class Method Summary collapse

Class Method Details

.switch_configuration(configuration_file) ⇒ Object

Switches the configuration for the given block

It switches the system configuration by reading a completely different file.

This makes for some interesting usage when you don't want to have multiple calls with a different GAUDI_CONFIG parameter


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gaudi/helpers/configuration.rb', line 27

def self.switch_configuration configuration_file
  if block_given?
    current_configuration =  ENV['GAUDI_CONFIG']
    if File.expand_path(configuration_file) != File.expand_path(current_configuration)
      begin
        puts "Switching configuration to #{configuration_file}"
        $configuration=nil
        ENV['GAUDI_CONFIG'] = configuration_file
        $configuration=Gaudi::Configuration::SystemConfiguration.load([ENV['GAUDI_CONFIG']])
        yield
      ensure
        puts "Switching configuration back to #{current_configuration}"
        $configuration=nil
        ENV['GAUDI_CONFIG'] = current_configuration
        $configuration=Gaudi::Configuration::SystemConfiguration.load([ENV['GAUDI_CONFIG']])
      end
    end
  end
end

.switch_platform_configuration(configuration_file, system_config, platform) ⇒ Object

Switches platform configuration replacing platform with the contents of the file for the given block


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gaudi/helpers/configuration.rb', line 48

def self.switch_platform_configuration configuration_file,system_config,platform
  if block_given?
    begin
      puts "Switching platform configuration for #{platform} to #{configuration_file}"
      current_config=system_config.platform_config(platform)
      new_cfg_data=system_config.read_configuration(File.expand_path(configuration_file))
      system_config.set_platform_config(PlatformConfiguration.new(platform,new_cfg_data),platform)
      yield
    rescue
      raise
    ensure
      puts "Switching back platform configuration for #{platform}"
      system_config.set_platform_config(current_config,platform)
    end
  end
end