<commit_before>##
# State Transition 是状态迁移。
# #reason 是原因。
# #subject 是状态的主体。

class Unidom::Action::StateTransition < Unidom::Action::ApplicationRecord

  self.table_name = 'unidom_state_transitions'

  include Unidom::Common::Concerns::ModelExtension

  belongs_to :transitor_visitor, polymorphic: true
  belongs_to :transitor_party,   polymorphic: true
  belongs_to :subject,           polymorphic: true
  belongs_to :reason,            class_name:  'Unidom::Action::Reason'

  scope :transited_via, ->(transitor_visitor) { where transitor_visitor: transitor_visitor }
  scope :transited_by,  ->(transitor_party)   { where transitor_party:   transitor_party   }
  scope :subject_is,    ->(subject)           { where subject:           subject           }
  scope :caused_by,     ->(reason)            { where reason_id:         to_id(reason)     }

  def self.transit!(subject: nil, from_state: nil, thru_state: nil, transitor_visitor: nil, transitor_party: nil, reason: nil, opened_at: Time.now)
    create! transitor_visitor: transitor_visitor, transitor_party: transitor_party, subject: subject, reason: reason, from_state: from_state, thru_state: thru_state, opened_at: opened_at
  end

end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Action::StateTransition'<commit_msg>1, Improve the State Transition model to include the As Caused concern.<commit_after>##
# State Transition 是状态迁移。
# #reason 是原因。
# #subject 是状态的主体。

class Unidom::Action::StateTransition < Unidom::Action::ApplicationRecord

  self.table_name = 'unidom_state_transitions'

  include Unidom::Common::Concerns::ModelExtension
  include Unidom::Action::Concerns::AsCaused

  belongs_to :transitor_visitor, polymorphic: true
  belongs_to :transitor_party,   polymorphic: true
  belongs_to :subject,           polymorphic: true

  scope :transited_via, ->(transitor_visitor) { where transitor_visitor: transitor_visitor }
  scope :transited_by,  ->(transitor_party)   { where transitor_party:   transitor_party   }
  scope :subject_is,    ->(subject)           { where subject:           subject           }

  def self.transit!(subject: nil, from_state: nil, thru_state: nil, transitor_visitor: nil, transitor_party: nil, reason: nil, opened_at: Time.now)
    create! transitor_visitor: transitor_visitor, transitor_party: transitor_party, subject: subject, reason: reason, from_state: from_state, thru_state: thru_state, opened_at: opened_at
  end

end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Action::StateTransition'
{'fraction_non_alphanumeric': 0.09940828402366864, 'fraction_numerical': 0.0003944773175542406, 'mean_word_length': 4.856812933025404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '1359391', 'n_tokens_mistral': 851, 'n_tokens_neox': 825, 'n_words': 182}