Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated models and added acts_as_auditable link to current work

  • Loading branch information...
commit 5d0ebe006a851db9b50aab09e489ead3e0c2d646 1 parent 7d724e8
Joshua Clayton authored
View
85 app/models/feed.rb
@@ -1,43 +1,58 @@
-class Feed < ActiveRecord::Base
- has_many :feed_statuses
- has_many :feed_items
-
- validates_uniqueness_of :url
-
- def feed; self.body_from(self.url); end
-
- def parse_feed
- rss = Hash.from_xml(self.feed)
- feed_items = self.source == "LastFM" ? rss["recenttracks"]["track"] : rss["rss"]["channel"]["item"]
- feed_items.each do |feed_item|
- item = initialize_feed_item(feed_item)
- item.save if item.valid?
- item.save_with_validation(false) if item.is_a?(LastFM)
+module Feeds
+ module Parsing
+ def self.included(base)
+ base.send :include, Feeds::Parsing::InstanceMethods
+ base.extend Feeds::Parsing::ClassMethods
end
- end
- class << self
- def sources; %w(Twitter LastFM Tumblr Flickr); end
- def parse_all
- Feed.find(:all).map(&:parse_feed)
+ module InstanceMethods
+ def feed
+ self.body_from(self.url)
+ end
+
+ def parse_feed
+ rss = Hash.from_xml(self.feed)
+ feed_items = self.source == "LastFM" ? rss["recenttracks"]["track"] : rss["rss"]["channel"]["item"]
+ feed_items.each do |feed_item|
+ item = initialize_feed_item(feed_item)
+ item.save if item.valid?
+ item.save_without_validation if item.is_a?(LastFM)
+ end
+ end
+
+ protected
+
+ def body_from(u)
+ url = URI.parse(u)
+ req = Net::HTTP::Get.new("#{url.path}?#{url.query}")
+ res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) }
+ FeedStatus.create(:response_code => res.code.to_i, :feed => self)
+ res.body
+ end
+
+ private
+
+ def initialize_feed_item(feed_item)
+ item = Object.const_get(self.source).new(feed_item)
+ item.feed, item.data = self, feed_item
+ item
+ end
+ end
+ module ClassMethods
+ def parse_all
+ Feed.all.map(&:parse_feed)
+ end
end
end
+end
+
+class Feed < ActiveRecord::Base
+ include Feeds::Parsing
- protected
+ SOURCES = %w(Twitter LastFM Tumblr Flickr)
- def body_from(u)
- url = URI.parse(u)
- req = Net::HTTP::Get.new("#{url.path}?#{url.query}")
- res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) }
- FeedStatus.create(:response_code => res.code.to_i, :feed => self)
- res.body
- end
-
- private
+ has_many :feed_statuses
+ has_many :feed_items
- def initialize_feed_item(feed_item)
- item = Object.const_get(self.source).new(feed_item)
- item.feed, item.data = self, feed_item
- item
- end
+ validates_uniqueness_of :url
end
View
2  app/models/feed_item.rb
@@ -14,6 +14,6 @@ def date=(time)
end
def self.types
- Feed.sources
+ Feed::SOURCES
end
end
View
0  app/models/flickr.rb → app/models/feed_items/flickr.rb
File renamed without changes
View
0  app/models/last_fm.rb → app/models/feed_items/last_fm.rb
File renamed without changes
View
0  app/models/tumblr.rb → app/models/feed_items/tumblr.rb
File renamed without changes
View
0  app/models/twitter.rb → app/models/feed_items/twitter.rb
File renamed without changes
View
4 app/views/home/index.html.erb
@@ -71,11 +71,13 @@
<dd>Ruby on Rails plugin for easy querying of ActiveRecord models by a string</dd>
<dt><%= link_to "acts_as_archivable", "http://github.com/joshuaclayton/acts_as_archivable/" %></dt>
<dd>Ruby on Rails plugin for easy querying of ActiveRecord models by a date</dd>
+ <dt><%= link_to "acts_as_auditable", "http://github.com/joshuaclayton/acts_as_auditable/" %></dt>
+ <dd>Ruby on Rails plugin for easy auditing (not versioning) of ActiveRecord models</dd>
<dt><%= link_to "Alpha Heroes", "http://www.alphaheroes.org/" %></dt>
<dd>Website dedicated to five Marines Alpha Co. 1/24 lost during their tour to Fallujah, Iraq</dd>
</dl>
<% end %>
-<% content :seven_twentyfourths, prepend_one_twentyfourth(), append_one_twentyfourth(), :last do %>
+<% content :seven_twentyfourths, prepend_one_twentyfourth, append_one_twentyfourth, :last do %>
<h2>Social Networking</h2>
<ul>
<li><%= link_to "GitHub", "http://github.com/joshuaclayton" %></li>
View
5 config/environment.rb
@@ -1,6 +1,3 @@
-RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
-
-# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
@@ -9,7 +6,7 @@
:session_key => '_jdclayton_session',
:secret => 'bab6dfb8ac69435a9a1b398c3856c2e563ddaa5409c2a7ca6db1ef55d8cb062af61d57c1d79eae30ad6f7c97a7b56f34452d63c546f269b86d7073dd679cfc5a'
}
-
+ config.load_paths += %W( #{RAILS_ROOT}/app/models/feed_items )
config.action_controller.session_store = :active_record_store
config.action_controller.page_cache_directory = "#{RAILS_ROOT}/public/cache/"
end
Please sign in to comment.
Something went wrong with that request. Please try again.