Sha256: 75050043d41bba37ace8b78be35e572ab0b4d83ca666c9775d70e922d6524952

Contents?: true

Size: 935 Bytes

Versions: 1

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

module CKEditor5::Rails
  module Context
    class Props
      include CKEditor5::Rails::Concerns::Checksum

      def initialize(config)
        @config = config
      end

      def to_attributes
        {
          **serialized_attributes,
          integrity: integrity_checksum
        }
      end

      private

      attr_reader :config

      def integrity_checksum
        unsafe_attributes = serialized_attributes.slice(:plugins)

        calculate_object_checksum(unsafe_attributes)
      end

      def serialized_attributes
        @serialized_attributes ||= {
          plugins: serialize_plugins,
          config: serialize_config
        }
      end

      def serialize_plugins
        (config[:plugins] || []).map { |plugin| Editor::PropsPlugin.normalize(plugin).to_h }.to_json
      end

      def serialize_config
        config.except(:plugins).to_json
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ckeditor5-1.16.0 lib/ckeditor5/rails/context/props.rb