<commit_before>module Edition::Workflow
  extend ActiveSupport::Concern

  module ClassMethods
    def active
      where(arel_table[:state].not_eq('archived'))
    end
  end

  included do
    include ::Transitions
    include ActiveRecord::Transitions

    default_scope where(arel_table[:state].not_eq('deleted'))

    define_model_callbacks :publish, :archive, :delete, only: :after
    set_callback :publish, :after do
      notify_observers :after_publish
    end
    set_callback :archive, :after do
      notify_observers :after_archive
    end
    set_callback :delete, :after do
      notify_observers :after_delete
    end

    after_publish :archive_previous_editions

    state_machine auto_scopes: true do
      state :draft
      state :submitted
      state :rejected
      state :published
      state :archived
      state :deleted

      event :delete, success: -> edition { edition.run_callbacks(:delete) } do
        transitions from: [:draft, :submitted, :rejected, :published, :archived], to: :deleted,
          guard: lambda { |d| d.draft? || d.submitted? || d.rejected? || d.only_edition? }
      end

      event :submit do
        transitions from: [:draft, :rejected], to: :submitted
      end

      event :reject do
        transitions from: :submitted, to: :rejected
      end

      event :publish, success: -> edition { edition.run_callbacks(:publish) } do
        transitions from: [:draft, :submitted], to: :published
      end

      event :archive, success: -> edition { edition.run_callbacks(:archive) } do
        transitions from: :published, to: :archived<commit_msg>Remove duplication in edition state machine gaurd clause.<commit_after>module Edition::Workflow
  extend ActiveSupport::Concern

  module ClassMethods
    def active
      where(arel_table[:state].not_eq('archived'))
    end
  end

  included do
    include ::Transitions
    include ActiveRecord::Transitions

    default_scope where(arel_table[:state].not_eq('deleted'))

    define_model_callbacks :publish, :archive, :delete, only: :after
    set_callback :publish, :after do
      notify_observers :after_publish
    end
    set_callback :archive, :after do
      notify_observers :after_archive
    end
    set_callback :delete, :after do
      notify_observers :after_delete
    end

    after_publish :archive_previous_editions

    state_machine auto_scopes: true do
      state :draft
      state :submitted
      state :rejected
      state :published
      state :archived
      state :deleted

      event :delete, success: -> edition { edition.run_callbacks(:delete) } do
        transitions from: [:draft, :submitted, :rejected, :published, :archived], to: :deleted,
          guard: lambda { |d| d.deletable? }
      end

      event :submit do
        transitions from: [:draft, :rejected], to: :submitted
      end

      event :reject do
        transitions from: :submitted, to: :rejected
      end

      event :publish, success: -> edition { edition.run_callbacks(:publish) } do
        transitions from: [:draft, :submitted], to: :published
      end

      event :archive, success: -> edition { edition.run_callbacks(:archive) } do
        transitions from: :published, to: :archived
{'fraction_non_alphanumeric': 0.09421641791044776, 'fraction_numerical': 0.0, 'mean_word_length': 3.08248730964467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3371897', 'n_tokens_mistral': 927, 'n_tokens_neox': 923, 'n_words': 263}