~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to lib/puppet/rails/param_value.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    belongs_to :param_name
8
8
    belongs_to :resource
9
9
 
 
10
    # Store a new parameter in a Rails db.
 
11
    def self.from_parser_param(param, values)
 
12
        values = munge_parser_values(values)
 
13
 
 
14
        param_name = Puppet::Rails::ParamName.find_or_create_by_name(param.to_s)
 
15
        return values.collect do |v|
 
16
            {:value => v, :param_name => param_name}
 
17
        end
 
18
    end
 
19
 
 
20
    # Make sure an array (or possibly not an array) of values is correctly
 
21
    # set up for Rails.  The main thing is that Resource::Reference objects
 
22
    # should stay objects, so they just get serialized.
 
23
    def self.munge_parser_values(value)
 
24
        values = value.is_a?(Array) ? value : [value]
 
25
        values.map do |v|
 
26
            if v.is_a?(Puppet::Resource::Reference)
 
27
                v
 
28
            else
 
29
                v.to_s
 
30
            end
 
31
        end
 
32
    end
 
33
 
 
34
 
10
35
    def value
11
36
        unserialize_value(self[:value])
12
37
    end
18
43
    end
19
44
 
20
45
    def to_label
21
 
      "#{self.param_name.name}"
 
46
        "#{self.param_name.name}"
22
47
    end
23
48
 
24
49
    # returns an array of hash containing all the parameters of a given resource
43
68
        params
44
69
    end
45
70
 
 
71
    def to_s
 
72
        "%s => %s" % [self.name, self.value]
 
73
    end
46
74
end
47