class Chef::Resource::PlistResource
Constants
- DEFAULTS_EXECUTABLE
- PLISTBUDDY_EXECUTABLE
- PLUTIL_EXECUTABLE
- PLUTIL_FORMAT_MAP
Public Instance Methods
Source
# File lib/chef/resource/plist.rb, line 142 def convert_to_data_type_from_string(type, value) case type when "boolean" # Since we've determined this is a boolean data type, we can assume that: # If the value as an int is 1, return true # If the value as an int is 0 (not 1), return false value.to_i == 1 when "integer" value.to_i when "float" value.to_f when "string", "dictionary" value when nil "" else raise "Unknown or unsupported data type: #{type.class}" end end
Question: Should I refactor these methods into an action_class? Answer: NO Why: We need them in both the action and in load_current_value. If you put them in the
action class then they're only in the Provider class and are not available to load_current_value
Source
# File lib/chef/resource/plist.rb, line 181 def entry_in_plist?(entry, path) print_entry = plistbuddy_command :print, entry, path cmd = shell_out print_entry cmd.exitstatus == 0 end
Source
# File lib/chef/resource/plist.rb, line 187 def plistbuddy_command(subcommand, entry, path, value = nil) sep = " " arg = case subcommand.to_s when "add" if value.is_a?(Hash) sep = ":" value.map { |k, v| "#{k} #{type_to_commandline_string(v)}" } else type_to_commandline_string(value) end when "set" if value.is_a?(Hash) sep = ":" value.map { |k, v| "#{k} #{v}" } else value end else "" end entry_with_arg = ["\"#{entry}\"", arg].join(sep).strip subcommand = "#{subcommand.capitalize} :#{entry_with_arg}" [PLISTBUDDY_EXECUTABLE, "-c", "\'#{subcommand}\'", "\"#{path}\""].join(" ") end
Source
# File lib/chef/resource/plist.rb, line 212 def setting_from_plist(entry, path) defaults_read_type_output = shell_out(DEFAULTS_EXECUTABLE, "read-type", path, entry).stdout data_type = defaults_read_type_output.split.last if value.class == Hash plutil_output = shell_out(PLUTIL_EXECUTABLE, "-extract", entry, "xml1", "-o", "-", path).stdout.chomp { key_type: data_type, key_value: ::Plist.parse_xml(plutil_output) } else defaults_read_output = shell_out(DEFAULTS_EXECUTABLE, "read", path, entry).stdout { key_type: data_type, key_value: defaults_read_output.strip } end end
Source
# File lib/chef/resource/plist.rb, line 162 def type_to_commandline_string(value) case value when Array "array" when Integer "integer" when FalseClass, TrueClass "bool" when Hash "dict" when String "string" when Float "float" else raise "Unknown or unsupported data type: #{value} of #{value.class}" end end