Class: Origen::SiteConfig

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/origen/site_config.rb', line 6

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]
  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