<commit_before>module SocialNetworking
  # Something to be completed by a Participant.
  class Goal < ActiveRecord::Base
    ACTION_TYPES = %w( created completed )
    Actions = Struct.new(*ACTION_TYPES.map(&:to_sym)).new(*ACTION_TYPES)

    belongs_to :participant
    has_many :comments, as: "item"
    has_many :likes, as: "item"

    validates :participant, :description, presence: true
    validates :is_completed, :is_deleted, inclusion: { in: [true, false] }
    validate :not_due_in_the_past, on: :create
    validate :due_before_membership_ends, on: :create

    def to_serialized
      if due_on
        {
          description: description,
          dueOn: due_on,
          dueOnDisplay: due_on ? due_on.strftime("%b. %e, %Y at %l:%M%p") : ""
        }
      else
        {}
      end
    end

    private

    def not_due_in_the_past
      return if due_on.nil? || due_on >= Date.today
<commit_msg>augment Goal to simplify finding and sharing past due Goals [#86332954]<commit_after>module SocialNetworking
  # Something to be completed by a Participant.
  class Goal < ActiveRecord::Base
    # create a mini DSL for types of Goal actions
    ACTION_TYPES = %w( created completed did_not_complete )
    Actions = Struct.new(*ACTION_TYPES.map(&:to_sym))
              .new(*(ACTION_TYPES.map { |t| t.gsub(/_/, " ") }))

    belongs_to :participant
    has_many :comments, as: "item"
    has_many :likes, as: "item"

    validates :participant, :description, presence: true
    validates :is_completed, :is_deleted, inclusion: { in: [true, false] }
    validate :not_due_in_the_past, on: :create
    validate :due_before_membership_ends, on: :create

    scope :did_not_complete, (lambda do
      where(is_completed: false).where(arel_table[:due_on].lt(Date.today))
    end)

    def to_serialized
      if due_on
        {
          description: description,
          dueOn: due_on,
          dueOnDisplay: due_on ? due_on.strftime("%b. %e, %Y at %l:%M%p") : ""
        }
      else
        {}
      end
    end

    private

    def not_due_in_the_past
      return if due_on.nil? || due_on >= Date.today

{'fraction_non_alphanumeric': 0.10660377358490566, 'fraction_numerical': 0.0037735849056603774, 'mean_word_length': 2.8704379562043796, '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': '2631111', 'n_tokens_mistral': 729, 'n_tokens_neox': 701, 'n_words': 178}