<commit_before>class Feed < ActiveRecord::Base

  # Associations -------------------------------------------------------

  has_many :articles

  # Validations --------------------------------------------------------

  validates_presence_of(:title)
  validates_presence_of(:url)

  # Instance Methods ---------------------------------------------------
 
  def update_meta(parser = Feedjira::Feed)
    feed = parser.fetch_and_parse(url)
    self.update_attributes!(title: feed.title)
  end

  def update_articles(parser = Feedjira::Feed)
    feed = parser.fetch_and_parse(url)
    
    feed.entries.each do |entry|
      article = Article.where(url: entry.url).first

      if article.nil?
        article = Article.new(title: entry.title,
                              url: entry.url,
                              summary: entry.summary)
        article.save!
      else
        article.update_attributes!(title: entry.title,
                                   url: entry.url,
                                   summary: entry.summary)
      end
    end
  end

end
<commit_msg>Make association on creation<commit_after>class Feed < ActiveRecord::Base

  # Associations -------------------------------------------------------

  has_many :articles

  # Validations --------------------------------------------------------

  validates_presence_of(:title)
  validates_presence_of(:url)

  # Instance Methods ---------------------------------------------------
 
  def update_meta(parser = Feedjira::Feed)
    feed = parser.fetch_and_parse(url)
    self.update_attributes!(title: feed.title)
  end

  def update_articles(parser = Feedjira::Feed)
    feed = parser.fetch_and_parse(url)
    
    feed.entries.each do |entry|
      article = Article.where(url: entry.url).first

      if article.nil?
        article = Article.new(title: entry.title,
                              url: entry.url,
                              summary: entry.summary,
                              feed: self)
        article.save!
      else
        article.update_attributes!(title: entry.title,
                                   url: entry.url,
                                   summary: entry.summary,
                                   feed: self)
      end
    end
  end

end

{'fraction_non_alphanumeric': 0.2146643109540636, 'fraction_numerical': 0.0, 'mean_word_length': 1.2011661807580174, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1258109', 'n_tokens_mistral': 573, 'n_tokens_neox': 539, 'n_words': 109}