diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-06-17 21:41:50 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-06-17 21:41:50 +0000 |
| commit | 46252b5bb858a1f2b87cc8646f3a59f935c58061 (patch) | |
| tree | 47d016a74967ae7fac18b711dcf7c8a998730d9d /lib | |
| parent | 6084e1a0efa2165e5cb10fff9ef0b06c1560f9c0 (diff) | |
All rails and language tests now pass again. All of the rails tests should now be in the rails/ directory, and I have modified resource translation so that it always converts single-member arrays to singe values, which means the rails collection does not need to worry about it.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2597 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/parser/resource.rb | 11 | ||||
| -rw-r--r-- | lib/puppet/parser/resource/param.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/rails/resource.rb | 15 |
3 files changed, 20 insertions, 8 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 25c9ab707..0722f388c 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -356,7 +356,16 @@ class Puppet::Parser::Resource av } end - obj[p.to_s] = v + + # If the value is an array with only one value, then + # convert it to a single value. This is largely so that + # the database interaction doesn't have to worry about + # whether it returns an array or a string. + obj[p.to_s] = if v.is_a?(Array) and v.length == 1 + v[0] + else + v + end end obj.file = self.file diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb index c719a7fd8..4d95db46a 100644 --- a/lib/puppet/parser/resource/param.rb +++ b/lib/puppet/parser/resource/param.rb @@ -22,7 +22,7 @@ class Puppet::Parser::Resource::Param # 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.map { |v| v.to_s } param_name = Puppet::Rails::ParamName.find_or_create_by_name(self.name.to_s) line_number = line_to_i() diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb index 2f58681ab..0163394b1 100644 --- a/lib/puppet/rails/resource.rb +++ b/lib/puppet/rails/resource.rb @@ -35,7 +35,7 @@ class Puppet::Rails::Resource < ActiveRecord::Base # returns a hash of param_names.name => [param_values] def get_params_hash(values = nil) values ||= param_values.find(:all, :include => :param_name) - return values.inject({}) do | hash, value | + values.inject({}) do | hash, value | hash[value.param_name.name] ||= [] hash[value.param_name.name] << value hash @@ -69,12 +69,15 @@ class Puppet::Rails::Resource < ActiveRecord::Base end def parameters - return self.param_values.find(:all, - :include => :param_name).inject({}) do |hash, pvalue| - hash[pvalue.param_name.name] ||= [] - hash[pvalue.param_name.name] << pvalue.value - hash + result = get_params_hash + result.each do |param, value| + if value.is_a?(Array) + result[param] = value.collect { |v| v.value } + else + result[param] = value.value + end end + result end def ref |
