<commit_before># Acting 是行为记录。
# #reason 是原因。
# #acted 是被操作的对象。
# #action_code 是行为代码，C: create, R: read, U: update, D: destroy。

class Unidom::Action::Acting < Unidom::Action::ApplicationRecord

  self.table_name = 'unidom_actings'

  include Unidom::Common::Concerns::ModelExtension

  belongs_to :actor_visitor, polymorphic: true
  belongs_to :actor_party,   polymorphic: true
  belongs_to :acted,         polymorphic: true
  belongs_to :reason,        class_name:  'Unidom::Action::Reason'

  scope :acted_via, ->(actor_visitor) { where actor_visitor: actor_visitor }
  scope :acted_by,  ->(actor_party)   { where actor_party:   actor_party   }
  scope :acted_is,  ->(acted)         { where acted:         acted         }
  scope :caused_by, ->(reason)        { where reason_id:     to_id(reason) }

end<commit_msg>1, Improve the Acting model to add the .act! method.<commit_after># Acting 是行为记录。
# #reason 是原因。
# #acted 是被操作的对象。
# #action_code 是行为代码，C: create, R: read, U: update, D: destroy。

class Unidom::Action::Acting < Unidom::Action::ApplicationRecord

  self.table_name = 'unidom_actings'

  include Unidom::Common::Concerns::ModelExtension

  belongs_to :actor_visitor, polymorphic: true
  belongs_to :actor_party,   polymorphic: true
  belongs_to :acted,         polymorphic: true
  belongs_to :reason,        class_name:  'Unidom::Action::Reason'

  scope :acted_via, ->(actor_visitor) { where actor_visitor: actor_visitor }
  scope :acted_by,  ->(actor_party)   { where actor_party:   actor_party   }
  scope :acted_is,  ->(acted)         { where acted:         acted         }
  scope :caused_by, ->(reason)        { where reason_id:     to_id(reason) }

  def self.act!(it, from: nil, thru: nil, due_to: nil, by: nil, via: nil, at: Time.now, action_code: 'C')
    create! from_value: from, thru_value: thru, actor_visitor: via, actor_party: by, acted: it, reason: due_to, action_code: action_code, opened_at: at
  end

end
{'fraction_non_alphanumeric': 0.1211340206185567, 'fraction_numerical': 0.0005154639175257732, 'mean_word_length': 3.9389312977099236, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3291196', 'n_tokens_mistral': 742, 'n_tokens_neox': 713, 'n_words': 170}