Class: Origen::SiteConfig

Inherits:
Object show all
Defined in:
lib/origen/site_config.rb

Constant Summary collapse

TRUE_VALUES =
['true', 'TRUE', '1', 1]
FALSE_VALUES =
['false', 'FALSE', '0', 0]

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/origen/site_config.rb', line 9

def method_missing(method, *args, &block)
  method = method.to_s
  if method =~ /(.*)!$/
    method = Regexp.last_match(1)
    must_be_present = true
  end
  env = "ORIGEN_#{method.upcase}"
  if ENV.key?(env)
    val = ENV[env]
    if TRUE_VALUES.include?(val)
      val = true
    elsif FALSE_VALUES.include?(val)
      val = false
    end
  else
    config = configs.find { |c| c.key?(method) }
    val = config ? config[method] : nil
  end
  if must_be_present && val.nil?
    puts "No value assigned for site_config attribute '#{method}'"
    puts
    fail 'Missing site_config value!'
  end
  define_singleton_method(method) do
    val
  end
  val
end