Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordanielgrippi <danielgrippi@gmail.com>2011-07-10 03:19:34 +0400
committerRaphael Sofaer <raphael@joindiaspora.com>2011-07-12 02:06:35 +0400
commit67882c775e7dcb701f5910fd8581c1de0f3fafa3 (patch)
treecebd3aa134e8fd043ccf2978d6217f2c9cc6a637 /lib
parentd364f158b8c08700a468b3fd28bbc1169a70bb67 (diff)
Addded Diaspora::Likeable module. Corrected the unique index for likes to include author_id; extracted before_save callback needed for tags into Diaspora::Taggable.
Diffstat (limited to 'lib')
-rw-r--r--lib/diaspora/likeable.rb20
-rw-r--r--lib/diaspora/taggable.rb2
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/diaspora/likeable.rb b/lib/diaspora/likeable.rb
new file mode 100644
index 000000000..6d0fc532d
--- /dev/null
+++ b/lib/diaspora/likeable.rb
@@ -0,0 +1,20 @@
+# Copyright (c) 2010, Diaspora Inc. This file is
+# licensed under the Affero General Public License version 3 or later. See
+# the COPYRIGHT file.
+
+module Diaspora
+ module Likeable
+ def self.included(model)
+ model.instance_eval do
+ has_many :likes, :conditions => {:positive => true}, :dependent => :delete_all, :as => :target
+ has_many :dislikes, :conditions => {:positive => false}, :class_name => 'Like', :dependent => :delete_all, :as => :target
+ end
+ end
+
+ # @return [Integer]
+ def update_likes_counter
+ self.likes_count = self.likes.count
+ self.save
+ end
+ end
+end
diff --git a/lib/diaspora/taggable.rb b/lib/diaspora/taggable.rb
index 8302cbe81..0c706a8eb 100644
--- a/lib/diaspora/taggable.rb
+++ b/lib/diaspora/taggable.rb
@@ -11,6 +11,8 @@ module Diaspora
cattr_accessor :field_with_tags
end
model.instance_eval do
+ before_create :build_tags
+
def extract_tags_from sym
self.field_with_tags = sym
end