lib/eucalypt/static.rb in eucalypt-0.3.3 vs lib/eucalypt/static.rb in eucalypt-0.3.4

- old
+ new

@@ -25,11 +25,11 @@ FILE_TYPES.each {|t, e| file_type = t if e.include? extension} raise TypeError.new("Unsupported extension: .#{extension}") if file_type.nil? define_singleton_method Inflect.resource_keep_inflection(file_name) do hash = parse(file_type, file) hash = hash ? hash : {} - symbolize ? hash.deep_symbolize_keys : hash + symbolize ? symbolize_keys(hash) : hash end end def define_subdirectory_accessor(subdirectory, symbolize) subdirectory_name = subdirectory.split(File::SEPARATOR).last @@ -42,7 +42,45 @@ case file_type when :yaml then YAML.load_file(file) when :json then JSON.parse(File.read file) end end + + def symbolize_keys(obj) + + case obj + + when Array + obj.inject([]){|res, val| + res << case val + when Hash, Array + symbolize_keys(val) + else + val + end + res + } + + when Hash + obj.inject({}){|res, (key, val)| + nkey = case key + when String + key.to_sym + else + key + end + nval = case val + when Hash, Array + symbolize_keys(val) + else + val + end + res[nkey] = nval + res + } + else + obj + end + end + end end \ No newline at end of file