summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/rails/reference_serializer.rb
blob: 9beeb00483cbeb5966432ee957b38d7b2da8d42b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

module Puppet::Util::ReferenceSerializer
  def unserialize_value(val)
    case val
    when /^--- /
      YAML.load(val)
    when "true"
      true
    when "false"
      false
    else
      val
    end
  end

  def serialize_value(val)
    case val
    when Puppet::Resource
      YAML.dump(val)
    when true, false
      # The database does this for us, but I prefer the
      # methods be their exact inverses.
      # Note that this means quoted booleans get returned
      # as actual booleans, but there doesn't appear to be
      # a way to fix that while keeping the ability to
      # search for parameters set to true.
      val.to_s
    else
      val
    end
  end
end