Sha256: 244bbc3ed7429674d7c52be32c02a765b0b0af05e5b0e44470fd13d9b026ab22

Contents?: true

Size: 1.06 KB

Versions: 22

Compression:

Stored size: 1.06 KB

Contents

module Workarea
  class Content
    class BlockDraft
      include ApplicationDocument

      field :content_id, type: String
      Block.fields.except('_id').each do |name, field_instance|
        field name, field_instance.options.except(:klass)
      end

      # Added as a field to ensure copying this value to any blocks created
      # from a draft.
      field :activate_with, 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?
        Configuration::ContentBlocks.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
        result = Content::Block.instantiate(as_document.except('content_id'))
        result.new_record = true
        result
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/content/block_draft.rb
workarea-core-3.5.26 app/models/workarea/content/block_draft.rb
workarea-core-3.5.25 app/models/workarea/content/block_draft.rb
workarea-core-3.5.23 app/models/workarea/content/block_draft.rb
workarea-core-3.5.22 app/models/workarea/content/block_draft.rb
workarea-core-3.5.21 app/models/workarea/content/block_draft.rb
workarea-core-3.5.20 app/models/workarea/content/block_draft.rb
workarea-core-3.5.19 app/models/workarea/content/block_draft.rb
workarea-core-3.5.18 app/models/workarea/content/block_draft.rb
workarea-core-3.5.17 app/models/workarea/content/block_draft.rb
workarea-core-3.5.16 app/models/workarea/content/block_draft.rb
workarea-core-3.5.15 app/models/workarea/content/block_draft.rb
workarea-core-3.5.14 app/models/workarea/content/block_draft.rb
workarea-core-3.5.13 app/models/workarea/content/block_draft.rb
workarea-core-3.5.12 app/models/workarea/content/block_draft.rb
workarea-core-3.5.11 app/models/workarea/content/block_draft.rb
workarea-core-3.5.10 app/models/workarea/content/block_draft.rb
workarea-core-3.5.9 app/models/workarea/content/block_draft.rb
workarea-core-3.5.8 app/models/workarea/content/block_draft.rb
workarea-core-3.5.7 app/models/workarea/content/block_draft.rb