<commit_before># == Schema Information
#
# Table name: payment_rules
#
#  id         :integer          not null, primary key
#  project_id :integer          not null
#  created_at :datetime         not null
#  updated_at :datetime         not null
#  frequency  :string           default("quarterly"), not null
#

class PaymentRule < ApplicationRecord
  include PaperTrailed
  delegate :program_id, to: :project

  FREQUENCIES = %w[monthly quarterly].freeze

  belongs_to :project, inverse_of: :payment_rules
  has_one :rule, dependent: :destroy, inverse_of: :payment_rule
  has_many :package_payment_rules, dependent: :destroy
  has_many :packages, through: :package_payment_rules, source: :package
  has_many :datasets, dependent: :destroy, class_name: PaymentRuleDataset

  accepts_nested_attributes_for :rule, allow_destroy: true

  validates :frequency, presence: true, inclusion: {
    in:      FREQUENCIES,
    message: "%{value} is not a valid see #{FREQUENCIES.join(',')}"
  }

  def dataset(given_frequency)
    datasets.detect { |ds| ds.frequency == given_frequency }
  end

  def code<commit_msg>class_name needs to be a symbol now<commit_after># == Schema Information
#
# Table name: payment_rules
#
#  id         :integer          not null, primary key
#  project_id :integer          not null
#  created_at :datetime         not null
#  updated_at :datetime         not null
#  frequency  :string           default("quarterly"), not null
#

class PaymentRule < ApplicationRecord
  include PaperTrailed
  delegate :program_id, to: :project

  FREQUENCIES = %w[monthly quarterly].freeze

  belongs_to :project, inverse_of: :payment_rules
  has_one :rule, dependent: :destroy, inverse_of: :payment_rule
  has_many :package_payment_rules, dependent: :destroy
  has_many :packages, through: :package_payment_rules, source: :package
  has_many :datasets, dependent: :destroy, class_name: "PaymentRuleDataset"

  accepts_nested_attributes_for :rule, allow_destroy: true

  validates :frequency, presence: true, inclusion: {
    in:      FREQUENCIES,
    message: "%{value} is not a valid see #{FREQUENCIES.join(',')}"
  }

  def dataset(given_frequency)
    datasets.detect { |ds| ds.frequency == given_frequency }
  end

  def code
{'fraction_non_alphanumeric': 0.09196428571428572, 'fraction_numerical': 0.0, 'mean_word_length': 3.903719912472648, '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': '3797537', 'n_tokens_mistral': 691, 'n_tokens_neox': 680, 'n_words': 195}