summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-25 21:07:20 +0100
committerJames Turnbull <james@lovedthanlost.net>2009-06-06 19:53:35 +1000
commit7666597edc335055275569f5626a897453402d5b (patch)
tree047ebd563f1044eba40bd6d6690b63988c166d7a /lib/puppet
parentd40068f7e70d1dc09334cac34d1bc48579b5a717 (diff)
downloadpuppet-7666597edc335055275569f5626a897453402d5b.tar.gz
puppet-7666597edc335055275569f5626a897453402d5b.tar.xz
puppet-7666597edc335055275569f5626a897453402d5b.zip
Allowing formats to specify the individual method names to use
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/network/format.rb50
1 files changed, 28 insertions, 22 deletions
diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb
index d50141ea9..5ed120ba6 100644
--- a/lib/puppet/network/format.rb
+++ b/lib/puppet/network/format.rb
@@ -6,39 +6,47 @@ require 'puppet/provider/confiner'
class Puppet::Network::Format
include Puppet::Provider::Confiner
- attr_reader :name, :mime, :weight, :required_methods
+ attr_reader :name, :mime
+ attr_accessor :intern_method, :render_method, :intern_multiple_method, :render_multiple_method, :weight, :required_methods
+
+ def init_attribute(name, default)
+ if value = @options[name]
+ @options.delete(name)
+ else
+ value = default
+ end
+ self.send(name.to_s + "=", value)
+ end
def initialize(name, options = {}, &block)
@name = name.to_s.downcase.intern
+ @options = options
+
# This must be done early the values can be used to set required_methods
define_method_names()
- if mime = options[:mime]
- self.mime = mime
- options.delete(:mime)
- else
- self.mime = "text/%s" % name
- end
+ method_list = {
+ :intern_method => "from_%s" % name,
+ :intern_multiple_method => "from_multiple_%s" % name,
+ :render_multiple_method => "to_multiple_%s" % name,
+ :render_method => "to_%s" % name
+ }
- if weight = options[:weight]
- @weight = weight
- options.delete(:weight)
- else
- @weight = 5
- end
+ init_attribute(:mime, "text/%s" % name)
+ init_attribute(:weight, 5)
+ init_attribute(:required_methods, method_list.keys)
- if methods = options[:required_methods]
- @required_methods = methods
- options.delete(:required_methods)
- else
- @required_methods = [:intern_method, :intern_multiple_method, :render_multiple_method, :render_method]
+ method_list.each do |method, value|
+ init_attribute(method, value)
end
- unless options.empty?
- raise ArgumentError, "Unsupported option(s) %s" % options.keys
+ unless @options.empty?
+ raise ArgumentError, "Unsupported option(s) %s" % @options.keys
end
+ @options = nil
+
instance_eval(&block) if block_given?
end
@@ -87,8 +95,6 @@ class Puppet::Network::Format
private
- attr_reader :intern_method, :render_method, :intern_multiple_method, :render_multiple_method
-
def define_method_names
@intern_method = "from_%s" % name
@render_method = "to_%s" % name