diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 02:08:11 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 02:08:11 +0000 |
| commit | dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126 (patch) | |
| tree | 6082433e05ad445aa4323a05de7d5820c5c023d6 /lib/puppet/parser/resource | |
| parent | 5a52855c1da2cb4716587bf0223c6d20eddaf00a (diff) | |
| download | puppet-dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126.tar.gz puppet-dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126.tar.xz puppet-dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126.zip | |
Fixing most of the rails stuff. I think everything basically works now, and now I am just going through and making sure things get deleted when they are supposed (i.e., you remove a resource and it gets deleted from the host's config).
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1950 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/resource')
| -rw-r--r-- | lib/puppet/parser/resource/param.rb | 43 |
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 |
