<commit_before>class Story < ActiveRecord::Base
  
  acts_as_commentable
  acts_as_taggable
  seo_urls
  acts_as_rateable :average => true

  belongs_to :publisher, :class_name => "User", :foreign_key => "publisher_id"  
  belongs_to :editor,    :class_name => "User", :foreign_key => "editor_id"  
  belongs_to :owner,     :class_name => "User", :foreign_key => "user_id"  

  named_scope :draft, :conditions => ['state = ?', 'draft']
  named_scope :archived, :conditions => ['archive_date <= ?', Time.now]
  named_scope :published, :conditions => ['publish_date <= ? and archive_date > ?', Time.now, Time.now]
  
  validates_presence_of :title, :body

  acts_as_state_machine :initial => :draft, :column => "state" 
  state :draft, :enter => :clean_dates
  state :archived, :enter => :set_archivation_date
  state :published, :enter => :set_publication_date

  event :publish do
    transitions :from => :draft, :to => :published
  end

  event :unpublish do
    transitions :from => :published, :to => :draft 
  end

  event :archive do
    transitions :from => :published, :to => :archived
  end
    
  event :unarchive do
    transitions :from => :archived, :to => :draft
  end
  
  def self.site_search(query, search_options={})
    sql = "%#{query}%"
    Story.published.find(:all, :conditions => ["title like ? or summary like ? or body like ?", sql, sql, sql])
  end

  def draft?
    self.state == 'draft'
  end  
  def published?
    !self.draft? && self.publish_date <= Time.now && self.archive_date > Time.now
  end
  def archived?
    !self.draft? && self.archive_date <= Time.now
  end

  def archivation_date(format=:short)
    I18n.l(self.archive_date, :format => format)
  end  
  def publication_date(format=:short)
    I18n.l(self.publish_date, :format => format)
  end

  private 
  
    def set_archivation_date
      self.archive_date = Time.now 
    end
    def set_publication_date
      self.publish_date = Time.now unless self.publish_date
      self.archive_date = Date.today + 1.year unless self.archive_date
    end<commit_msg>reimplemented state query methods<commit_after>class Story < ActiveRecord::Base
  
  acts_as_commentable
  acts_as_taggable
  seo_urls
  acts_as_rateable :average => true

  belongs_to :publisher, :class_name => "User", :foreign_key => "publisher_id"  
  belongs_to :editor,    :class_name => "User", :foreign_key => "editor_id"  
  belongs_to :owner,     :class_name => "User", :foreign_key => "user_id"  

  named_scope :draft, :conditions => ['state = ?', 'draft']
  named_scope :archived, :conditions => ['archive_date <= ?', Time.now]
  named_scope :published, :conditions => ['publish_date <= ? and archive_date > ?', Time.now, Time.now]
  
  validates_presence_of :title, :body

  acts_as_state_machine :initial => :draft, :column => "state" 
  state :draft, :enter => :clean_dates
  state :archived, :enter => :set_archivation_date
  state :published, :enter => :set_publication_date

  event :publish do
    transitions :from => :draft, :to => :published
  end

  event :unpublish do
    transitions :from => :published, :to => :draft 
  end

  event :archive do
    transitions :from => :published, :to => :archived
  end
    
  event :unarchive do
    transitions :from => :archived, :to => :draft
  end
  
  def self.site_search(query, search_options={})
    sql = "%#{query}%"
    Story.published.find(:all, :conditions => ["title like ? or summary like ? or body like ?", sql, sql, sql])
  end

  def draft?
    self.state == 'draft'
  end  
  def published?
    self.publish_date && self.archive_date && self.publish_date <= Time.now && self.archive_date > Time.now
  end
  def archived?
    self.archive_date && self.archive_date <= Time.now
  end

  def archivation_date(format=:short)
    I18n.l(self.archive_date, :format => format)
  end  
  def publication_date(format=:short)
    I18n.l(self.publish_date, :format => format)
  end

  private 
  
    def set_archivation_date
      self.archive_date = Time.now 
    end
    def set_publication_date
      self.publish_date = Time.now unless self.publish_date
      self.archive_date = Date.today + 1.year unless self.archive_date
    end
{'fraction_non_alphanumeric': 0.12797118847539016, 'fraction_numerical': 0.0024009603841536613, 'mean_word_length': 3.6651735722284435, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 59, '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': '1158577', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1391, 'n_words': 341}