lib/facter/util/utils.rb in facter-4.0.52 vs lib/facter/util/utils.rb in facter-4.1.0
- old
+ new
@@ -2,11 +2,11 @@
module Facter
module Utils
# Sort nested hash.
def self.sort_hash_by_key(hash, recursive = true, &block)
- hash.keys.sort(&block).each_with_object({}) do |key, seed|
+ hash.keys.sort(&block).each_with_object(hash.class.new) do |key, seed|
seed[key] = hash[key]
seed[key] = sort_hash_by_key(seed[key], true, &block) if recursive && seed[key].is_a?(Hash)
seed
end
@@ -26,8 +26,25 @@
when Array
object.map { |e| deep_stringify_keys(e) }
else
object
end
+ end
+
+ def self.try_to_bool(value)
+ case value.to_s
+ when 'true'
+ true
+ when 'false'
+ false
+ else
+ value
+ end
+ end
+
+ def self.try_to_int(value)
+ Integer(value)
+ rescue ArgumentError, TypeError
+ value
end
end
end