aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_text/attribute.rb
blob: 9d872a87a1748144e31b194f7755d6ee5f969943 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module ActiveText
  module Attribute
    extend ActiveSupport::Concern

    class_methods do
      def active_text_attribute(attribute_name)
        serialize(attribute_name, ActiveText::Content)

        has_many_attached "#{attribute_name}_attachments"

        after_save do
          blobs = public_send(attribute_name).attachments.map(&:attachable)
          public_send("#{attribute_name}_attachments_blobs=", blobs)
        end
      end
    end
  end
end