Есть две модели source.rb и feed_entry.rb с переходом на mongo не могу понять как сделать обновление feed_entries каждые 3 минуты выдает NoMethodError: private method `select' called for Source:Class
source.rb
class Source
include Mongoid::Document
include Mongoid::Timestamps
field :url, type: String
field :title, type: String
field :site, type: String
after_save :load_feed_entries
has_many :feed_entries, dependent: :destroy
def load_feed_entries
last_entry = self.feed_entries.last
if last_entry.nil?
feed = Feedjira::Feed.fetch_and_parse(self.url)
else
feed = Feedjira::Feed.fetch_and_parse(self.url,
:if_modified_since => last_entry.published_at.to_time)
end
Source.add_entries(feed.entries, self.id)
end
def self.update_all_feeds(urls)
Feedjira::Feed.fetch_and_parse(urls,
:on_success => lambda { |url, feed|
rss = Source.select("sources.id").where(:url => url).first
Source.add_entries(feed.entries, rss.id)
}
)
end
private
def self.add_entries(entries, stream_id)
entries.each do |entry|
unless FeedEntry.where(guid: entry.id).exists?
FeedEntry.create!(
:name => entry.title,
:summary => entry.summary,
:url => entry.url,
:content => entry.content,
:published_at => entry.published,
:guid => entry.id,
:source_id => stream_id,
)
end
end
end
end
feed_entry.rb
class FeedEntry
include Mongoid::Document
include Mongoid::Timestamps
field :content, type: String
field :guid, type: String
field :name, type: String
field :published_at, type: Time
field :summary, type: String
field :url, type: String
field :source_id, type: Integer
belongs_to :source, touch: true
validates :source_id, presence: true
end
feed.rake
task :collect => :environment do
urls = Source.select("sources.url").all.map { |v| v[:url] }
Source.update_all_feeds(urls)
end