Sha256: 0e884f1916a6ef7ded117007dddb86ec42aaad0c457f08eb2417deaafe2d3e37

Contents?: true

Size: 633 Bytes

Versions: 14

Compression:

Stored size: 633 Bytes

Contents

module Superstore
  module Types
    class JsonType < BaseType
      def encode(data)
        ActiveSupport::JSON.encode(data)
      end

      def decode(str)
        ActiveSupport::JSON.decode(str)
      end

      def typecast(data)
        return data if ActiveSupport.parse_json_times

        if data.acts_like?(:time) || data.acts_like?(:date)
          data.as_json
        elsif data.is_a?(Array)
          data.map { |d| typecast(d) }
        elsif data.is_a?(Hash)
          data.each_with_object({}) { |(key, value), hash| hash[key] = typecast(value) }
        else
          data
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
superstore-1.2.0 lib/superstore/types/json_type.rb
superstore-1.1.4 lib/superstore/types/json_type.rb
superstore-1.1.3 lib/superstore/types/json_type.rb
superstore-1.1.2 lib/superstore/types/json_type.rb
superstore-1.1.1 lib/superstore/types/json_type.rb
superstore-1.1.0 lib/superstore/types/json_type.rb
superstore-1.0.12 lib/superstore/types/json_type.rb
superstore-1.0.11 lib/superstore/types/json_type.rb
superstore-1.0.10 lib/superstore/types/json_type.rb
superstore-1.0.9 lib/superstore/types/json_type.rb
superstore-1.0.8 lib/superstore/types/json_type.rb
superstore-1.0.7 lib/superstore/types/json_type.rb
superstore-1.0.6 lib/superstore/types/json_type.rb
superstore-1.0.5 lib/superstore/types/json_type.rb