<commit_before>module Statusable
  extend ActiveSupport::Concern

  # To make a record schedulable, create a date column named scheduled_date

  included do
    parent_class = self

    enum status: {
      published: 1,
      # draft: 2,
      scheduled: 3,
      # pending: 4,
      hidden: 5
    }

    validates_presence_of :status

    before_save :check_active_scheduled_date

    scope :by_status, -> (status) { where(status: status) }
    scope :published_or_scheduled, -> {
      where("#{parent_class.model_name.plural}.status = :published OR (#{parent_class.model_name.plural}.status = :scheduled AND COALESCE(#{parent_class.model_name.plural}.scheduled_date, :date_yesterday) <= :date_today)",
        published: 1,
        scheduled: 3,
        date_today: Date.today,
        date_yesterday: Date.yesterday)
    }

    def self.statusable?
      true
    end

    def self.statuses_for_select
      if self.column_names.include?('scheduled_date')
        self.statuses
      else
        self.statuses.except(:scheduled)
      end
    end

    def statusable?
      true
    end

    private

      def check_active_scheduled_date
        if self.respond_to?(:scheduled_date)
          if self.scheduled_date <= Date.today
            self.status = 'published'
          end
        end
      end
  end
end<commit_msg>Don't crash a schedulable item if scheduled_date is nil<commit_after>module Statusable
  extend ActiveSupport::Concern

  # To make a record schedulable, create a date column named scheduled_date

  included do
    parent_class = self

    enum status: {
      published: 1,
      # draft: 2,
      scheduled: 3,
      # pending: 4,
      hidden: 5
    }

    validates_presence_of :status

    before_save :check_active_scheduled_date

    scope :by_status, -> (status) { where(status: status) }
    scope :published_or_scheduled, -> {
      where("#{parent_class.model_name.plural}.status = :published OR (#{parent_class.model_name.plural}.status = :scheduled AND COALESCE(#{parent_class.model_name.plural}.scheduled_date, :date_yesterday) <= :date_today)",
        published: 1,
        scheduled: 3,
        date_today: Date.today,
        date_yesterday: Date.yesterday)
    }

    def self.statusable?
      true
    end

    def self.statuses_for_select
      if self.column_names.include?('scheduled_date')
        self.statuses
      else
        self.statuses.except(:scheduled)
      end
    end

    def statusable?
      true
    end

    private

      def check_active_scheduled_date
        if self.respond_to?(:scheduled_date)
          if self.scheduled_date.present? && self.scheduled_date <= Date.today
            self.status = 'published'
          end
        end
      end
  end
end
{'fraction_non_alphanumeric': 0.08692476260043827, 'fraction_numerical': 0.005113221329437546, 'mean_word_length': 2.507042253521127, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7199801', 'n_tokens_mistral': 882, 'n_tokens_neox': 841, 'n_words': 190}