summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/resource
diff options
context:
space:
mode:
authorballman <ballman@980ebf18-57e1-0310-9a29-db15c13687c0>2007-06-12 00:31:16 +0000
committerballman <ballman@980ebf18-57e1-0310-9a29-db15c13687c0>2007-06-12 00:31:16 +0000
commit68e37a99d5357f022662f9ba7cc564c48aed21a9 (patch)
treee8d94cc9ea44d312e8b96f94c887b88fc1b04e0f /lib/puppet/parser/resource
parentc26f678178d173bd7360362b2959af51c4d39762 (diff)
downloadpuppet-68e37a99d5357f022662f9ba7cc564c48aed21a9.tar.gz
puppet-68e37a99d5357f022662f9ba7cc564c48aed21a9.tar.xz
puppet-68e37a99d5357f022662f9ba7cc564c48aed21a9.zip
Major rework of the rails feature. Changed the relationship between
host and facts (now many-to-many with fact_name through fact_values). Also changed the relationship between resource and params (similarly many-to-many with param_names through param_values). Added the resource_tags and puppet_tags. The latter has the tag names and the former is the man-to-many link with resources. There is a little clean up left but the schema is in order. Also a test for the tags stuff is required. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2565 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/resource')
-rw-r--r--lib/puppet/parser/resource/param.rb73
1 files changed, 46 insertions, 27 deletions
diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb
index dc325487c..34c260a44 100644
--- a/lib/puppet/parser/resource/param.rb
+++ b/lib/puppet/parser/resource/param.rb
@@ -15,43 +15,62 @@ class Puppet::Parser::Resource::Param
"#<#{self.class} @name => #{self.name}, @value => #{self.value}, @source => #{self.source.type}>"
end
- # Store this parameter in a Rails db.
- def to_rails(res, pn = nil)
+ def line_to_i
+ return line ? Integer(line) : nil
+ end
+
+ # Store a new parameter in a Rails db.
+ def to_rails(db_resource)
values = value.is_a?(Array) ? value : [value]
+ values.map! { |v| v.to_s }
- values = values.collect { |v| v.to_s }
-
- unless pn
- # We're creating it anew.
- pn = res.param_names.build(:name => self.name.to_s)
- end
-
- value_objects = []
+ param_name = Puppet::Rails::ParamName.find_or_create_by_name(self.name.to_s)
+ line_number = line_to_i()
- if l = self.line
- pn.line = Integer(l)
- end
-
- oldvals = []
-
- if pv = pn.param_values
- oldvals = pv.collect { |val| val.value }
+ return values.collect do |v|
+ db_resource.param_values.create(:value => v,
+ :line => line_number,
+ :param_name => param_name)
end
+ end
- if oldvals != values
- #pn.param_values = values.collect { |v| pn.param_values.build(:value => v.to_s) }
- objects = values.collect do |v|
- pn.param_values.build(:value => v.to_s)
- end
- pn.param_values = objects
- end
+ def modify_rails_values(db_values)
+ #dev_warn if db_values.nil? || db_values.empty?
- return pn
+ values_to_remove(db_values).each { |remove_me|
+ Puppet::Rails::ParamValue.delete(remove_me)
+ }
+ line_number = line_to_i()
+ values_to_add(db_values).each { |add_me|
+ db_resource = db_values[0].resource
+ db_param_name = db_values[0].param_name
+ db_resource.param_values.create(:value => add_me,
+ :line => line_number,
+ :param_name => db_param_name)
+ }
end
-
+
def to_s
"%s => %s" % [self.name, self.value]
end
+
+ def values_to_remove(db_values)
+ values = value.is_a?(Array) ? value : [value]
+ line_number = line_to_i()
+ db_values.collect do |db|
+ db unless (db.line == line_number &&
+ values.find { |v| v == db.value } )
+ end.compact
+ end
+
+ def values_to_add(db_values)
+ values = value.is_a?(Array) ? value : [value]
+ line_number = line_to_i()
+ values.collect do |v|
+ v unless db_values.find { |db| (v == db.value &&
+ line_number == db.line) }
+ end.compact
+ end
end
# $Id$