<commit_before>class Api::V1::PostResource < JSONAPI::Resource
  before_create :set_author_as_current_user
  before_update :set_editor_as_current_user

  attributes :banner_url,
             :content,
             :slug,
             :title,
             :group_slug,
             :tags

  attribute :published_at, format: :iso8601
  attribute :updated_at, format: :iso8601

  has_one :author, class_name: 'User'
  has_one :editor, class_name: 'User'
  has_one :group

  filter :group

  def group_slug
    @model.group.slug
  end

  def tags
    @model.tag_list
  end

  def tags=(tags)
    @model.tag_list = tags
  end

  private

  def self.apply_filter(records, filter, value, options)
    case filter
    when :group
      records.where(group_id: value)
    else
      return super(records, filter, value, options)
    end
  end

  def set_author_as_current_user
    @model.author = context[:current_user]
  end

  def set_editor_as_current_user
    @model.editor = context[:current_user]
  end
end
<commit_msg>Move attribute changes to after_replace_fields<commit_after>class Api::V1::PostResource < JSONAPI::Resource
  after_replace_fields :set_author_as_current_user
  after_replace_fields :set_editor_as_current_user

  attributes :banner_url,
             :content,
             :slug,
             :title,
             :group_slug,
             :tags

  attribute :published_at, format: :iso8601
  attribute :updated_at, format: :iso8601

  has_one :author, class_name: 'User'
  has_one :editor, class_name: 'User'
  has_one :group

  filter :group

  def group_slug
    @model.group.slug
  end

  def tags
    @model.tag_list
  end

  def tags=(tags)
    @model.tag_list = tags
  end

  private

  def self.apply_filter(records, filter, value, options)
    case filter
    when :group
      records.where(group_id: value)
    else
      return super(records, filter, value, options)
    end
  end

  def set_author_as_current_user
    @model.author ||= context[:current_user]
  end

  def set_editor_as_current_user
    @model.editor = context[:current_user]
  end
end

{'fraction_non_alphanumeric': 0.07976934166266218, 'fraction_numerical': 0.008649687650168188, 'mean_word_length': 2.9961612284069097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4316173', 'n_tokens_mistral': 704, 'n_tokens_neox': 683, 'n_words': 160}