<commit_before>class EmailSignup
  # pull in enough of active model to be able to use this in a form
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  def persisted?
    false
  end

  validates :alerts, length: { minimum: 1 }
  validate :all_alerts_are_valid

  def alerts=(new_alerts)
    @alerts = Array.wrap(new_alerts).map { |new_alert| build_alert(new_alert) }
  end

  def alerts
    @alerts || []
  end

  def build_alert(args = {})
    case args
    when EmailSignup::Alert
      args
    when Hash
      EmailSignup::Alert.new(args)
    else
      raise ArgumentError, "can't construct an Alert out of #{args.inspect}"
    end
  end

  def self.valid_topics
    Classification.order(:name).where("(type = 'Topic' and published_policies_count <> 0) or (type = 'TopicalEvent')").alphabetical
  end
  def self.valid_topic_slugs
    valid_topics.map(&:slug) + ['all']
  end

  def self.valid_organisations_by_type
    ministerial_department_type = OrganisationType.find_by_name('Ministerial department')
    sub_organisation_type = OrganisationType.find_by_name('Sub-organisation')
    {
      ministerial: Organisation.with_translations.where("organisation_type_id = ? AND govuk_status ='live'", ministerial_department_type),
      other: Organisation.with_translations.where("organisation_type_id NOT IN (?,?) AND govuk_status='live'", ministerial_department_type, sub_organisation_type)
    }
  end
  def self.valid_organisation_slugs
    valid_organisations_by_type.values.flatten.map(&:slug) + ['all']
  end

  def self.valid_document_types_by_type
    {
      publication_type: [DocumentTypeOptionForAllOfType.new('All publication types')] + Whitehall::PublicationFilterOption.all.sort_by { |o| o.label },
      announcement_type: [DocumentTypeOptionForAllOfType.new('All announcment types')] + Whitehall::AnnouncementFilterOption.all.sort_by { |o| o.label },
      policy_type: [DocumentTypeOptionForAllOfType.new('All policies')]
    }<commit_msg>Juggle functional programming in EmailSignup to make 1.9.2 mocking happy<commit_after>class EmailSignup
  # pull in enough of active model to be able to use this in a form
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  def persisted?
    false
  end

  validates :alerts, length: { minimum: 1 }
  validate :all_alerts_are_valid

  def alerts=(new_alerts)
    @alerts = Array.wrap(new_alerts).map { |new_alert| build_alert(new_alert) }
  end

  def alerts
    @alerts || []
  end

  def build_alert(args = {})
    case args
    when EmailSignup::Alert
      args
    when Hash
      EmailSignup::Alert.new(args)
    else
      raise ArgumentError, "can't construct an Alert out of #{args.inspect}"
    end
  end

  def self.valid_topics
    Classification.order(:name).where("(type = 'Topic' and published_policies_count <> 0) or (type = 'TopicalEvent')").alphabetical
  end
  def self.valid_topic_slugs
    valid_topics.map(&:slug) + ['all']
  end

  def self.valid_organisations_by_type
    ministerial_department_type = OrganisationType.find_by_name('Ministerial department')
    sub_organisation_type = OrganisationType.find_by_name('Sub-organisation')
    {
      ministerial: Organisation.with_translations.where("organisation_type_id = ? AND govuk_status ='live'", ministerial_department_type),
      other: Organisation.with_translations.where("organisation_type_id NOT IN (?,?) AND govuk_status='live'", ministerial_department_type, sub_organisation_type)
    }
  end
  def self.valid_organisation_slugs
    valid_organisations_by_type.map { |type, orgs| orgs.map(&:slug) }.flatten + ['all']
  end

  def self.valid_document_types_by_type
    {
      publication_type: [DocumentTypeOptionForAllOfType.new('All publication types')] + Whitehall::PublicationFilterOption.all.sort_by { |o| o.label },
      announcement_type: [DocumentTypeOptionForAllOfType.new('All announcment types')] + Whitehall::AnnouncementFilterOption.all.sort_by { |o| o.label },
      policy_type: [DocumentTypeOptionForAllOfType.new('All policies')]
    }
{'fraction_non_alphanumeric': 0.09970745977571917, 'fraction_numerical': 0.0017064846416382253, 'mean_word_length': 4.567164179104478, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5687548', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1310, 'n_words': 271}