Module: Chef::Mixin::PowershellTypeCoercions

Included in:
Provider::DscResource
Defined in:
lib/chef/mixin/powershell_type_coercions.rb

Instance Method Summary collapse

Instance Method Details

#translate_type(value) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/mixin/powershell_type_coercions.rb', line 37

def translate_type(value)
  translation = type_coercions[value.class]

  if translation
    translation[:type].call(value)
  elsif value.respond_to? :to_psobject
    "(#{value.to_psobject})"
  else
    safe_string(value.to_s)
  end
end

#type_coercionsObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/chef/mixin/powershell_type_coercions.rb', line 24

def type_coercions
  @type_coercions ||= {
    Fixnum => { :type => lambda { |x| x.to_s } },
    Float => { :type => lambda { |x| x.to_s } },
    FalseClass => { :type => lambda { |x| "$false" } },
    TrueClass => { :type => lambda { |x| "$true" } },
    Hash => { :type => Proc.new { |x| translate_hash(x) } },
    Array => { :type => Proc.new { |x| translate_array(x) } },
    Chef::Node::ImmutableMash => { :type => Proc.new { |x| translate_hash(x) } },
    Chef::Node::ImmutableArray => { :type => Proc.new { |x| translate_array(x) } },
  }
end