# File lib/puppet/sslcertificates/support.rb, line 12
12:   def self.keytype(name, options, &block)
13:     var = "@#{name}"
14: 
15:     maker = "mk_#{name}"
16:     reader = "read_#{name}"
17: 
18:     unless param = options[:param]
19:       raise ArgumentError, "You must specify the parameter for the key"
20:     end
21: 
22:     unless klass = options[:class]
23:       raise ArgumentError, "You must specify the class for the key"
24:     end
25: 
26:     # Define the method that creates it.
27:     define_method(maker, &block)
28: 
29:     # Define the reading method.
30:     define_method(reader) do
31:       return nil unless FileTest.exists?(Puppet[param]) or rename_files_with_uppercase(Puppet[param])
32: 
33:       begin
34:         instance_variable_set(var, klass.new(File.read(Puppet[param])))
35:       rescue => detail
36:         raise InvalidCertificate, "Could not read #{param}: #{detail}"
37:       end
38:     end
39: 
40:     # Define the overall method, which just calls the reader and maker
41:     # as appropriate.
42:     define_method(name) do
43:       unless cert = instance_variable_get(var)
44:         unless cert = send(reader)
45:           cert = send(maker)
46:           Puppet.settings.write(param) { |f| f.puts cert.to_pem }
47:         end
48:         instance_variable_set(var, cert)
49:       end
50:       cert
51:     end
52:   end