<commit_before>module ActionText
  module Attribute
    extend ActiveSupport::Concern

    class_methods do
      def has_rich_text(name)
        class_eval <<-CODE, __FILE__, __LINE__ + 1
          def #{name}
            self.rich_text_#{name} ||= ActionText::RichText.new(name: "#{name}", record: self)
          end

          def #{name}=(body)
            #{name}.body = body
          end
        CODE

        has_one :"rich_text_#{name}", -> { where(name: name) }, class_name: "ActionText::RichText", as: :record, inverse_of: :record, dependent: :destroy

        scope :"with_rich_text_#{name}", -> { includes("rich_text_#{name}") }

        after_save { public_send(name).save if public_send(name).changed? }
      end
    end
  end<commit_msg>Add scope to preload embeds as well<commit_after>module ActionText
  module Attribute
    extend ActiveSupport::Concern

    class_methods do
      def has_rich_text(name)
        class_eval <<-CODE, __FILE__, __LINE__ + 1
          def #{name}
            self.rich_text_#{name} ||= ActionText::RichText.new(name: "#{name}", record: self)
          end

          def #{name}=(body)
            #{name}.body = body
          end
        CODE

        has_one :"rich_text_#{name}", -> { where(name: name) }, class_name: "ActionText::RichText", as: :record, inverse_of: :record, dependent: :destroy

        scope :"with_rich_text_#{name}", -> { includes("rich_text_#{name}") }
        scope :"with_rich_text_#{name}_and_embeds", -> { includes("rich_text_#{name}": { embeds_attachments: :blob }) }

        after_save { public_send(name).save if public_send(name).changed? }
      end
    end
  end
{'fraction_non_alphanumeric': 0.13861985472154964, 'fraction_numerical': 0.0012106537530266344, 'mean_word_length': 2.7739726027397262, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2824437', 'n_tokens_mistral': 523, 'n_tokens_neox': 518, 'n_words': 112}