lib/scout/indiferent_hash/options.rb in scout-gear-2.0.0 vs lib/scout/indiferent_hash/options.rb in scout-gear-5.1.1

- old
+ new

@@ -1,34 +1,26 @@ module IndiferentHash def self.add_defaults(options, defaults = {}) - options ||= {} + options = string2hash options if String === options IndiferentHash.setup(options) - case - when Hash === options - new_options = options.dup - when String === options - new_options = string2hash options - else - raise "Format of '#{options.inspect}' not understood. It should be a hash" - end + defaults = string2hash defaults if String === defaults + defaults.each do |key, value| next if options.include? key - new_options[key] = value + options[key] = value end - new_options - - options.replace new_options + options end def self.process_options(hash, *keys) IndiferentHash.setup(hash) defaults = keys.pop if Hash === keys.last - hahs = IndiferentHash.add_defaults hash, defaults if defaults + hash = IndiferentHash.add_defaults hash, defaults if defaults if keys.length == 1 hash.include?(keys.first.to_sym) ? hash.delete(keys.first.to_sym) : hash.delete(keys.first.to_s) else keys.collect do |key| hash.include?(key.to_sym) ? hash.delete(key.to_sym) : hash.delete(key.to_s) end @@ -100,11 +92,11 @@ def self.string2hash(string) options = {} string.split('#').each do |str| - key, sep, value = str.partition "=" + key, _, value = str.partition "=" key = key[1..-1].to_sym if key[0] == ":" options[key] = true and next if value.empty? options[key] = value[1..-1].to_sym and next if value[0] == ":" @@ -112,20 +104,10 @@ options[key] = value[1..-2] and next if value =~ /^['"].*['"]$/ options[key] = value.to_i and next if value =~ /^\d+$/ options[key] = value.to_f and next if value =~ /^\d*\.\d+$/ options[key] = true and next if value == "true" options[key] = false and next if value == "false" - options[key] = value and next - - options[key] = begin - saved_safe = $SAFE - $SAFE = 0 - eval(value) - rescue Exception - value - ensure - $SAFE = saved_safe - end + options[key] = value end IndiferentHash.setup(options) end end