lib/jsonapi/formatter.rb in jsonapi-resources-0.8.3 vs lib/jsonapi/formatter.rb in jsonapi-resources-0.9.0.beta1

- old
+ new

@@ -11,10 +11,14 @@ def cached return FormatterWrapperCache.new(self) end + def uncached + return self + end + def formatter_for(format) "#{format.to_s.camelize}Formatter".safe_constantize end end end @@ -78,10 +82,14 @@ end def cached self end + + def uncached + return @formatter_klass + end end end class UnderscoredKeyFormatter < JSONAPI::KeyFormatter end @@ -111,10 +119,16 @@ end class DefaultValueFormatter < JSONAPI::ValueFormatter class << self def format(raw_value) - raw_value + case raw_value + when Date, Time, DateTime, ActiveSupport::TimeWithZone, BigDecimal + # Use the as_json methods added to various base classes by ActiveSupport + return raw_value.as_json + else + return raw_value + end end end end class IdValueFormatter < JSONAPI::ValueFormatter