summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/resource
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/resource')
-rw-r--r--lib/puppet/parser/resource/param.rb43
1 files changed, 31 insertions, 12 deletions
diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb
index 2e5d78034..6f24f1486 100644
--- a/lib/puppet/parser/resource/param.rb
+++ b/lib/puppet/parser/resource/param.rb
@@ -16,22 +16,41 @@ class Puppet::Parser::Resource::Param
end
# Store this parameter in a Rails db.
- def store(resource)
- args = {}
- #[:name, :value, :line, :file].each do |var|
- [:name, :value].each do |var|
- args[var] = self.send(var)
+ def to_rails(res)
+ values = value.is_a?(Array) ? value : [value]
+
+ unless pn = res.param_names.find_by_name(self.name.to_s)
+ # We're creating it anew.
+ pn = res.param_names.build(:name => self.name.to_s)
+ end
+
+ if l = self.line
+ pn.line = Integer(l)
+ end
+
+ exists = {}
+ pn.param_values.each { |pv| exists[pv.value] = pv }
+ values.each do |value|
+ unless pn.param_values.find_by_value(value)
+ pn.param_values.build(:value => value)
+ end
+ # Mark that this is still valid.
+ if exists.include?(value)
+ exists.delete(value)
+ end
end
- args[:name] = args[:name].to_s
- args[:name].each do |name|
- pn = resource.param_names.find_or_create_by_name(name)
- args[:value].each do |value|
- pv = pn.param_values.find_or_create_by_value(value)
+
+ # And remove any existing values that are not in the current value list.
+ unless exists.empty?
+ # We have to save the current state else the deletion somehow deletes
+ # our new values.
+ pn.save
+ exists.each do |value, obj|
+ pn.param_values.delete(obj)
end
end
- obj = resource.param_names.find_by_name(args[:name], :include => :param_values)
- return obj
+ return pn
end
def to_s