lib/models.rb in cachai-0.0.5 vs lib/models.rb in cachai-0.0.7
- old
+ new
@@ -20,26 +20,57 @@
true
rescue ActiveRecord::StatementInvalid => e
# SQLite3::SQLException => e
# return !e.message['no such table']
false
+ rescue ActiveRecord::ConnectionNotEstablished
+ puts "Connection not established."
+ false
end
+ def self.domain=(value)
+ @domain = value
+ end
+
+ def self.domain
+ @domain
+ end
+
+ def self.cache=(obj)
+ @cache = obj
+ end
+
+ def self.cache
+ @cache
+ end
+
+ def self.clear_cache(path)
+ cache.del(key_for(path))
+ end
+
+ def self.key_for(path)
+ raise "Domain not set!" unless @domain
+ "comments:#{@domain}:#{path}"
+ end
+
class Post < ActiveRecord::Base
has_many :responses
validates_presence_of :path
validates_uniqueness_of :path
def self.find_or_create_by_path(path)
find_by_path(path) || create({:path => path})
end
+ def clear_cache
+ Cachai.clear_cache(path)
+ end
end
class Response < ActiveRecord::Base
belongs_to :post
- validates_presence_of :author_name, :author_name, :author_email, :content
+ validates_presence_of :author_name, :author_email, :content
scope :approved, lambda { where(:approved => 1) }
scope :comment, lambda { where(:response_type => 'comment') }
scope :pingback, lambda { where(:response_type => 'pingback') }
scope :top_level, lambda { where(:parent_id => 0) }