Browse files

Merge pull request #10 from patcon/resource-attr-user

Add `user` resource attr to `mac_os_x_userdefaults`
  • Loading branch information...
2 parents e0fc88f + 4dad5cb commit 554ce45321df60edfcceed23f7d7276777cab4fd @jtimberman jtimberman committed Jan 27, 2013
Showing with 8 additions and 2 deletions.
  1. +1 −0 README.md
  2. +6 −2 providers/userdefaults.rb
  3. +1 −0 resources/userdefaults.rb
View
1 README.md
@@ -51,6 +51,7 @@ Manage the Mac OS X user defaults(1) system. The parameters to the resource are
- key: The preference key. Required.
- value: The value of the key. Required.
- type: Value type of the preference key.
+- user: User for which to set the default.
- sudo: Set to true if the setting requires privileged access to modify. Default false.
`value` settings of `1`, `TRUE`, `true`, `YES` or `yes` are treated as true by defaults(1), and are handled in the provider.
View
8 providers/userdefaults.rb
@@ -31,7 +31,9 @@ def load_current_resource
drcmd = "defaults read #{new_resource.domain} "
drcmd << "-g " if new_resource.global
drcmd << "#{new_resource.key} " if new_resource.key
- v = shell_out("#{drcmd} | grep -qx '#{truefalse || new_resource.value}'")
+ shell_out_opts = {}
+ shell_out_opts[:user] = new_resource.user unless new_resource.user.nil?
+ v = shell_out("#{drcmd} | grep -qx '#{truefalse || new_resource.value}'", shell_out_opts)
is_set = v.exitstatus == 0 ? true : false
@userdefaults.is_set(is_set)
end
@@ -67,7 +69,9 @@ def load_current_resource
cmd << "-#{type}" if type
cmd << value
- execute cmd.join(' ')
+ execute cmd.join(' ') do
+ user new_resource.user unless new_resource.user.nil?
+ end
new_resource.updated_by_last_action(true)
end
end
View
1 resources/userdefaults.rb
@@ -24,6 +24,7 @@
attribute :key, :kind_of => String, :default => nil
attribute :value, :kind_of => [Integer,Float,String,TrueClass,FalseClass,Hash], :default => nil, :required => true
attribute :type, :kind_of => String, :default => nil
+attribute :user, :kind_of => String, :default => nil
attribute :sudo, :kind_of => [TrueClass, FalseClass], :default => false
attribute :is_set, :kind_of => [TrueClass, FalseClass], :default => false

0 comments on commit 554ce45

Please sign in to comment.