Class: UU::OS::Env::Environment

Inherits:
Object
  • Object
show all
Defined in:
uu_os_framework-0.29.16/lib/uu/os/env/environment.rb

Overview

Provides operations for the current execution environment.

Constant Summary

Class Method Summary (collapse)

Class Method Details

+ (Hash) load_configuration(path)

Loads configuration file (in property format).

Parameters:

  • path (String)

    Path to configuration file (absolute or relative to UU Home)

Returns:

  • (Hash)

    Hash containing parsed configuration file



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'uu_os_framework-0.29.16/lib/uu/os/env/environment.rb', line 43

def self.load_configuration(path)
  if !Pathname.new(path).absolute?
    path = File.join(self.uu_home, path)
  end
  if !File.exist?(path)
    raise ArgumentError.new("Configuration file #{path} does not exist.")
  end
  properties = {}
  File.open(path, 'rt') do |file|
    content = file.read
    properties = self.parse_properties(content)
  end
  properties
end

+ (Hash) parse_properties(data)

Parses data in Java properties format and returns it as a hash.

Parameters:

  • data (String)

    The data to parse.

Returns:

  • (Hash)

    A hash containing the parsed properties.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'uu_os_framework-0.29.16/lib/uu/os/env/environment.rb', line 62

def self.parse_properties(data)
  properties = {}
  data.gsub!(/\r\n?/, "\n")
  data.each_line do |line|
    line.strip!
    if (line[0] != ?# and line[0] != ?=)
      i = line.index('=')
      if (i)
        properties[line[0..i - 1].strip] = line[i + 1..-1].strip
      else
        properties[line] = ''
      end
    end
  end
  properties
end

+ (String) uu_home

Returns directory which should (by default) contain all application configuration files. It may be defined by environment variable UU_HOME and defaults to '~/.uu'

Returns:

  • (String)

    UU Home directory



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'uu_os_framework-0.29.16/lib/uu/os/env/environment.rb', line 23

def self.uu_home
  path = Java::JavaLang::System.getProperty('uu.home') if RUBY_PLATFORM[/java/] 
  path = ENV['UU_HOME'] if path.nil?
  if path.nil?
    result = Pathname.new(File.join(Dir.home, '.uu'))
  else
    result = Pathname.new(path)
  end
  if !@@CONFIG_INITIALIZED
    self.send(:init_config, result)
    @@CONFIG_INITIALIZED = true
  end
  result
end