Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from bleything/tweak_userdefaults

Tweak userdefaults
  • Loading branch information...
commit 9029336deb791e2a58dc8a10e1ca638758e888bf 2 parents 39ff26d + 268f0aa
@jtimberman jtimberman authored
Showing with 22 additions and 6 deletions.
  1. +21 −5 providers/userdefaults.rb
  2. +1 −1  resources/userdefaults.rb
View
26 providers/userdefaults.rb
@@ -37,11 +37,27 @@ def load_current_resource
action :write do
unless @userdefaults.is_set
- cmd = "#{'sudo' if new_resource.sudo} defaults write #{new_resource.domain} "
- cmd << "-g " if new_resource.global
- cmd << "'#{new_resource.key}' " if new_resource.key
- cmd << "-#{new_resource.type} " if new_resource.type
+ cmd = ["defaults write"]
+ cmd.unshift('sudo') if new_resource.sudo
+
+ if new_resource.global
+ cmd << "NSGlobalDomain"
+ else
+ cmd << new_resource.domain
+ end
+
+ cmd << "'#{new_resource.key}'" if new_resource.key
+
+ type = new_resource.type
+ type ||= case new_resource.value
+ when TrueClass, FalseClass
+ 'bool'
+ when Integer
+ 'int'
+ end
+
+ cmd << "-#{type}" if type
cmd << "'#{new_resource.value}'"
- execute cmd
+ execute cmd.join(' ')
end
end
View
2  resources/userdefaults.rb
@@ -22,7 +22,7 @@
attribute :domain, :kind_of => String, :name_attribute => true, :required => true
attribute :global, :kind_of => [TrueClass, FalseClass], :default => false
attribute :key, :kind_of => String, :default => nil
-attribute :value, :kind_of => [Integer,String], :default => nil, :required => true
+attribute :value, :kind_of => [Integer,String,TrueClass,FalseClass], :default => nil, :required => true
attribute :type, :kind_of => String, :default => nil
attribute :sudo, :kind_of => [TrueClass, FalseClass], :default => false
attribute :is_set, :kind_of => [TrueClass, FalseClass], :default => false
Please sign in to comment.
Something went wrong with that request. Please try again.