Skip to content

Commit

Permalink
now passing the post object along with the entry object to entries_be…
Browse files Browse the repository at this point in the history
…come block
  • Loading branch information
nakajima committed Sep 23, 2008
1 parent 94e78e7 commit 5c6d414
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def entries_become(entry_type, &block)
has_many entry_type, :foreign_key => :feed_id, :dependent => :destroy
define_method(:refresh!) do
logger.debug "=> creating #{entry_type} from #{uri}"
entries.each(&block.bind(self))
entries.each { |entry| block.call(send(entry_type).build, entry) }
self.updated_at = Time.now
self.save
end
Expand Down
5 changes: 3 additions & 2 deletions app/models/feeds/blog.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Blog < Feed

entries_become :articles do |entry|
article = articles.build :content => entry.content, :header => entry.title
entries_become :articles do |article, entry|
article.header = entry.title
article.content = entry.content
article.permalink = entry.urls.first
article.created_at = entry.try(:date_published)
article.updated_at = entry.try(:last_updated)
Expand Down
6 changes: 4 additions & 2 deletions app/models/feeds/delicious.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Delicious < Feed

entries_become :links do |entry|
link = links.build :permalink => entry.urls.first, :header => entry.title, :content => entry.content
entries_become :links do |link, entry|
link.header = entry.title
link.content = entry.content
link.permalink = entry.urls.first
link.created_at = entry.date_published
link.save
end
Expand Down
12 changes: 5 additions & 7 deletions app/models/feeds/flickr.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
class Flickr < Feed

entries_become :pictures do |entry|
doc = Hpricot(entry.content)
picture = pictures.build \
:permalink => (doc/"img").first['src'].gsub(/_m/, ''),
:header => entry.title,
:cite => entry.urls.first
# picture.created_at = entry.try(:date_published)
entries_become :pictures do |picture, entry|
picture.cite = entry.urls.first
picture.header = entry.title
picture.permalink = (Hpricot(entry.content)/"img").first['src'].gsub(/_m/, '')
picture.created_at = entry.try(:date_published)
picture.updated_at = entry.try(:last_updated)
picture.save
end
Expand Down
5 changes: 3 additions & 2 deletions app/models/feeds/twitter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Twitter < Feed

entries_become :tweets do |entry|
tweet = tweets.build :permalink => entry.urls.first, :content => entry.content.gsub(/\A\w*:?\s/, '')
entries_become :tweets do |tweet, entry|
tweet.content = entry.content.gsub(/\A\w*:?\s/, '')
tweet.permalink = entry.urls.first
tweet.created_at = entry.try(:date_published)
tweet.save ? tweet : tweet.destroy
end
Expand Down

0 comments on commit 5c6d414

Please sign in to comment.