Sha256: 7e2289cf2932089508830e4258e9b1b36a683c911a2dcd26a917df0d290b52e0

Contents?: true

Size: 792 Bytes

Versions: 34

Compression:

Stored size: 792 Bytes

Contents

module Workarea
  class Content
    class BlockDraft
      include ApplicationDocument
      include Mongoid::Attributes::Dynamic

      field :content_id, type: String

      index(
        { created_at: 1 },
        { expire_after_seconds: 1.hour.seconds.to_i }
      )

      before_save :typecast_data!

      def content
        Content.find(content_id)
      end

      def block_type
        return unless type_id.present?
        Workarea.config.content_block_types.detect { |bt| bt.id == type_id.to_sym }
      end

      def typecast_data!
        return unless type_id.present? && data.present?
        self.data = block_type.try(:typecast!, data)
        self
      end

      def to_block
        content.blocks.build(attributes.except('content_id'))
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 app/models/workarea/content/block_draft.rb
workarea-core-3.4.44 app/models/workarea/content/block_draft.rb
workarea-core-3.4.43 app/models/workarea/content/block_draft.rb
workarea-core-3.4.42 app/models/workarea/content/block_draft.rb
workarea-core-3.4.41 app/models/workarea/content/block_draft.rb
workarea-core-3.4.40 app/models/workarea/content/block_draft.rb
workarea-core-3.4.39 app/models/workarea/content/block_draft.rb
workarea-core-3.4.38 app/models/workarea/content/block_draft.rb
workarea-core-3.4.37 app/models/workarea/content/block_draft.rb
workarea-core-3.4.36 app/models/workarea/content/block_draft.rb
workarea-core-3.4.35 app/models/workarea/content/block_draft.rb
workarea-core-3.4.34 app/models/workarea/content/block_draft.rb
workarea-core-3.4.33 app/models/workarea/content/block_draft.rb
workarea-core-3.4.32 app/models/workarea/content/block_draft.rb
workarea-core-3.4.31 app/models/workarea/content/block_draft.rb
workarea-core-3.4.30 app/models/workarea/content/block_draft.rb
workarea-core-3.4.29 app/models/workarea/content/block_draft.rb
workarea-core-3.4.28 app/models/workarea/content/block_draft.rb
workarea-core-3.4.27 app/models/workarea/content/block_draft.rb
workarea-core-3.4.26 app/models/workarea/content/block_draft.rb