Class: Configtemplate::ConfigTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/configtemplate.rb

Instance Method Summary collapse

Constructor Details

#initialize(configfile, environment) ⇒ ConfigTemplate

Returns a new instance of ConfigTemplate.



14
15
16
17
18
19
20
21
22
23
# File 'lib/configtemplate.rb', line 14

def initialize(configfile, environment)
  conf = YAML.load_file configfile
  raise "No such environment: #{environment}" if not conf.has_key? environment
  env = conf[environment]
  if conf.has_key? 'default'
    env = conf['default'].merge env
  end
  env['environment_name'] = environment
  @binding = make_binding env
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



36
37
38
# File 'lib/configtemplate.rb', line 36

def method_missing(name, *args, &block)
  get name
end

Instance Method Details

#convert_file(infile, outfile) ⇒ Object



25
26
27
28
29
30
# File 'lib/configtemplate.rb', line 25

def convert_file(infile, outfile)
  e = ERB.new File.open(infile).read
  File.open(outfile, 'w') { |f| 
    f.write e.result(@binding)
  }
end

#get(name) ⇒ Object



32
33
34
# File 'lib/configtemplate.rb', line 32

def get(name)
  eval name.to_s, @binding
end