summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/resource
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-08 16:56:41 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-04-22 14:39:36 +1000
commit6314745c054ba9482f145b4ec798431ac2f300a3 (patch)
tree851f037a5aad8af01949ea8e9d82c369f1c9a2b6 /lib/puppet/parser/resource
parentbe30a618272d9828f90f5e726a23021be3b23221 (diff)
downloadpuppet-6314745c054ba9482f145b4ec798431ac2f300a3.tar.gz
puppet-6314745c054ba9482f145b4ec798431ac2f300a3.tar.xz
puppet-6314745c054ba9482f145b4ec798431ac2f300a3.zip
Refactoring the Rails integration
This moves all code from the Parser class into the ActiveRecord classes, and gets rid of 'ar_hash_merge'. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/parser/resource')
-rw-r--r--lib/puppet/parser/resource/param.rb72
1 files changed, 0 insertions, 72 deletions
diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb
index 7ce58f4c4..6e22d3e17 100644
--- a/lib/puppet/parser/resource/param.rb
+++ b/lib/puppet/parser/resource/param.rb
@@ -22,80 +22,8 @@ class Puppet::Parser::Resource::Param
def line_to_i
return line ? Integer(line) : nil
end
-
- # Make sure an array (or possibly not an array) of values is correctly
- # set up for Rails. The main thing is that Resource::Reference objects
- # should stay objects, so they just get serialized.
- def munge_for_rails(values)
- values = value.is_a?(Array) ? value : [value]
- values.map do |v|
- if v.is_a?(Puppet::Parser::Resource::Reference)
- v
- else
- v.to_s
- end
- end
- end
-
- # Store a new parameter in a Rails db.
- def to_rails(db_resource)
- values = munge_for_rails(value)
-
- param_name = Puppet::Rails::ParamName.find_or_create_by_name(self.name.to_s)
- line_number = line_to_i()
- return values.collect do |v|
- db_resource.param_values.create(:value => v,
- :line => line_number,
- :param_name => param_name)
- end
- end
-
- def modify_rails_values(db_values)
- #dev_warn if db_values.nil? || db_values.empty?
-
- values_to_remove(db_values).each { |remove_me|
- Puppet::Rails::ParamValue.delete(remove_me['id'])
- }
- line_number = line_to_i()
- db_param_name = db_values[0]['param_name_id']
- values_to_add(db_values).each { |add_me|
- Puppet::Rails::ParamValue.create(:value => add_me,
- :line => line_number,
- :param_name_id => db_param_name,
- :resource_id => db_values[0]['resource_id'] )
- }
- end
def to_s
"%s => %s" % [self.name, self.value]
end
-
- def compare(v,db_value)
- if (v.is_a?(Puppet::Parser::Resource::Reference))
- return v.to_s == db_value.to_s
- else
- return v == db_value
- end
- end
-
- def values_to_remove(db_values)
- values = munge_for_rails(value)
- line_number = line_to_i()
- db_values.collect do |db|
- db unless (db['line'] == line_number &&
- values.find { |v|
- compare(v,db['value'])
- } )
- end.compact
- end
-
- def values_to_add(db_values)
- values = munge_for_rails(value)
- line_number = line_to_i()
- values.collect do |v|
- v unless db_values.find { |db| (compare(v,db['value']) &&
- line_number == db['line']) }
- end.compact
- end
end
-