Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add hashes to userdefaults #6

Merged
merged 1 commit into from

2 participants

@bleything

more type inference for userdefaults. Now it knows hashes.

@jtimberman jtimberman merged commit 6385426 into chef-osx:master
@jtimberman
Owner

Zomg <3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 25, 2011
  1. @bleything
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 8 deletions.
  1. +13 −7 providers/userdefaults.rb
  2. +1 −1  resources/userdefaults.rb
View
20 providers/userdefaults.rb
@@ -49,15 +49,21 @@ def load_current_resource
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
+ value = "'#{new_resource.value}'"
+ case new_resource.value
+ when TrueClass, FalseClass
+ type ||= 'bool'
+ when Integer
+ type ||= 'int'
+ when Hash
+ type ||= 'dict'
+
+ # creates a string of Key1 Value1 Key2 Value2...
+ value = new_resource.value.map {|k,v| "\"#{k}\" \"#{v}\"" }.join(' ')
+ end
cmd << "-#{type}" if type
- cmd << "'#{new_resource.value}'"
+ cmd << value
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,TrueClass,FalseClass], :default => nil, :required => true
+attribute :value, :kind_of => [Integer,String,TrueClass,FalseClass,Hash], :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.