Set up the feed_item model
[feedcatcher.git] / app / models / feed_item.rb
diff --git a/app/models/feed_item.rb b/app/models/feed_item.rb
new file mode 100644 (file)
index 0000000..db0613d
--- /dev/null
@@ -0,0 +1,22 @@
+class FeedItem < ActiveRecord::Base
+  validates_presence_of :feed_name, :title, :description
+  validates_uniqueness_of :title, :scope => :feed_name
+  validate :feed_name_must_be_legal
+
+  def FeedItem.valid_feed_name?(feed_name)
+    Rack::Utils::escape(feed_name) == feed_name and
+      Rack::Utils::unescape(feed_name) == feed_name and
+      feed_name != 'index' and
+      feed_name != 'show' and
+      feed_name != 'update' and
+      feed_name != 'action'
+  end
+
+  private
+
+  def feed_name_must_be_legal
+    unless FeedItem.valid_feed_name?(feed_name)
+      errors.add(:feed_name, 'is invalid')
+    end
+  end
+end