lib/rabl/builder.rb in rabl-0.9.3 vs lib/rabl/builder.rb in rabl-0.9.4.pre1
- old
+ new
@@ -42,18 +42,34 @@
update_settings(:child)
update_settings(:glue)
wrap_result(options[:root_name])
- replace_nil_values if Rabl.configuration.replace_nil_values_with_empty_strings
+ replace_nil_values if Rabl.configuration.replace_nil_values_with_empty_strings
+ replace_empty_string_values if Rabl.configuration.replace_empty_string_values_with_nil_values
+ remove_nil_values if Rabl.configuration.exclude_nil_values
# Return Results
@_root_name ? { @_root_name => @_result } : @_result
end
def replace_nil_values
@_result = @_result.inject({}) do |hash, (k, v)|
hash[k] = v.nil? ? '' : v
+ hash
+ end
+ end
+
+ def replace_empty_string_values
+ @_result = @_result.inject({}) do |hash, (k, v)|
+ hash[k] = (!v.nil? && v != "") ? v : nil
+ hash
+ end
+ end
+
+ def remove_nil_values
+ @_result = @_result.inject({}) do |hash, (k, v)|
+ hash[k] = v unless v.nil?
hash
end
end
def wrap_result(root_name)