Sha256: fd849010ae923144ce48c7ef9041e9512d8d018dc472247e1d558ae7f446df34

Contents?: true

Size: 685 Bytes

Versions: 4

Compression:

Stored size: 685 Bytes

Contents

# frozen_string_literal: true

module Katalyst
  module Content
    module Types
      # Data serialization/deserialization for Katalyst::Content::Item style data
      class StyleType < ActiveRecord::Type::Json
        def initialize(type)
          super()

          @type = type
        end

        def serialize(value)
          super(value.attributes)
        end

        def deserialize(value)
          case value
          when String
            decoded = super
            @type.new(**decoded) unless decoded.nil?
          when Hash
            @type.new(**value)
          when HasStyle::StyleBase
            value
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
katalyst-content-2.7.0 app/models/katalyst/content/types/style_type.rb
katalyst-content-2.6.2 app/models/katalyst/content/types/style_type.rb
katalyst-content-2.6.1 app/models/katalyst/content/types/style_type.rb
katalyst-content-2.6.0 app/models/katalyst/content/types/style_type.rb