/usr/lib/ruby/vendor_ruby/cheffish/array_property.rb is in ruby-cheffish 4.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | require 'chef/property'
module Cheffish
# A typical array property. Defaults to [], accepts multiple args to setter, accumulates values.
class ArrayProperty < Chef::Property
def initialize(**options)
options[:is] ||= Array
options[:default] ||= []
options[:coerce] ||= proc { |v| v.is_a?(Array) ? v : [ v ] }
super
end
# Support my_property 'a', 'b', 'c'; my_property 'a'; and my_property ['a', 'b']
def emit_dsl
declared_in.class_eval(<<-EOM, __FILE__, __LINE__+1)
def #{name}(*values)
property = self.class.properties[#{name.inspect}]
if values.empty?
property.get(self)
elsif property.is_set?(self)
property.set(self, property.get(self) + values.flatten)
else
property.set(self, values.flatten)
end
end
EOM
end
end
end
|