<commit_before># == Schema Information
#
# Table name: events
#
#  id           :integer          not null, primary key
#  title        :string(255)      not null
#  created_at   :datetime
#  updated_at   :datetime
#  organizer_id :integer
#  published    :boolean          default(FALSE)
#  description  :text
#  started_at   :datetime
#  title_image  :string(255)
#  place        :string(255)
#  published_at :datetime
#  slug         :string(255)
#  location     :string
#

class Event < ActiveRecord::Base
  mount_uploader :title_image, EventTitleImageUploader

  belongs_to :organizer, class_name: 'User'

  has_many :event_participations
  has_many :participants, class_name: 'User', through: :event_participations, source: :user

  validates :title, presence: true
  validates :organizer, presence: true
  validates :place, presence: true
  validates :description, presence: true
  validates :started_at, presence: true

  scope :ordered_desc,  -> { order(started_at: :desc) }
  scope :ordered_asc,   -> { order(started_at: :asc) }

  scope :published, -> { where(published: true) }

  scope :past,    -> { ordered_desc.where("started_at < ?", Time.now.beginning_of_day ) }
  scope :future,  -> { ordered_asc.where("started_at >= ?", Time.now.beginning_of_day ) }

  scope :held_in,  -> (year, month) {
    start   = month.nil? ? Date.new(year) : Date.new(year, month)
    finish  = month.nil? ? start.end_of_year : start.end_of_month
    ordered_desc.where("started_at BETWEEN ? AND ?", start, finish)
  }

  scope :visible_by_user, -> (user) {
    return published if user.nil?
    user.admin? ? all : where("organizer_id = ? OR published = ?", user.id, true)
  }


  extend FriendlyId
  friendly_id :slug_candidates, use: :slugged

  def slug_candidates
    [[ started_at.strftime("%Y-%m-%d"), title ]]
  end

  def user_participated?(user)
    user && event_participations.find_by(user_id: user.id)
  end<commit_msg>Respect history of slugs<commit_after># == Schema Information
#
# Table name: events
#
#  id           :integer          not null, primary key
#  title        :string(255)      not null
#  created_at   :datetime
#  updated_at   :datetime
#  organizer_id :integer
#  published    :boolean          default(FALSE)
#  description  :text
#  started_at   :datetime
#  title_image  :string(255)
#  place        :string(255)
#  published_at :datetime
#  slug         :string(255)
#  location     :string
#

class Event < ActiveRecord::Base
  mount_uploader :title_image, EventTitleImageUploader

  belongs_to :organizer, class_name: 'User'

  has_many :event_participations
  has_many :participants, class_name: 'User', through: :event_participations, source: :user

  validates :title, presence: true
  validates :organizer, presence: true
  validates :place, presence: true
  validates :description, presence: true
  validates :started_at, presence: true

  scope :ordered_desc,  -> { order(started_at: :desc) }
  scope :ordered_asc,   -> { order(started_at: :asc) }

  scope :published, -> { where(published: true) }

  scope :past,    -> { ordered_desc.where("started_at < ?", Time.now.beginning_of_day ) }
  scope :future,  -> { ordered_asc.where("started_at >= ?", Time.now.beginning_of_day ) }

  scope :held_in,  -> (year, month) {
    start   = month.nil? ? Date.new(year) : Date.new(year, month)
    finish  = month.nil? ? start.end_of_year : start.end_of_month
    ordered_desc.where("started_at BETWEEN ? AND ?", start, finish)
  }

  scope :visible_by_user, -> (user) {
    return published if user.nil?
    user.admin? ? all : where("organizer_id = ? OR published = ?", user.id, true)
  }


  extend FriendlyId
  friendly_id :slug_candidates, use: :history

  def slug_candidates
    [[ started_at.strftime("%Y-%m-%d"), title ]]
  end

  def user_participated?(user)
    user && event_participations.find_by(user_id: user.id)
  end
{'fraction_non_alphanumeric': 0.12315653298835705, 'fraction_numerical': 0.006209573091849935, 'mean_word_length': 3.569739952718676, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '3174570', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1289, 'n_words': 298}