Skip to content

Loading…

Tweak userdefaults #3

Merged
merged 4 commits into from

2 participants

@bleything

This adds type inference for Integer and Boolean values as well as correcting a bug wherein it was possible to double-specify the domain by using the global flag.

bleything added some commits
@bleything bleything allow booleans as values; automatically set type for booleans 8ed19a3
@bleything bleything fix domain specification
-g is a shortcut for specifying NSGlobalDomain. As it was, it was
possible to specify a domain and mark the setting as global, which is
incorrect and would fail. This change makes anything marked as global go
into NSGlobalDomain.
86b0f9c
@bleything bleything switch to a command array, trailing spaces are too error-prone 7c19dcf
@bleything bleything add type inference for Integers 268f0aa
@jtimberman jtimberman merged commit 9029336 into chef-osx:master
@jtimberman
Chef Cookbooks for Mac OS X member

Most bestest! Thanks! :D

@jtimberman
Chef Cookbooks for Mac OS X member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 9, 2011
  1. @bleything
  2. @bleything

    fix domain specification

    bleything committed
    -g is a shortcut for specifying NSGlobalDomain. As it was, it was
    possible to specify a domain and mark the setting as global, which is
    incorrect and would fail. This change makes anything marked as global go
    into NSGlobalDomain.
  3. @bleything
  4. @bleything
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.