jackdempsey-acts_as_commentable 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +12 -2
- data/init.rb +1 -4
- data/lib/acts_as_commentable.rb +2 -66
- data/lib/commentable_methods.rb +66 -0
- metadata +3 -2
data/README
CHANGED
@@ -13,11 +13,21 @@ Install
|
|
13
13
|
|
14
14
|
script/plugin install http://github.com/jackdempsey/acts_as_commentable.git
|
15
15
|
|
16
|
+
* To install as a gem
|
17
|
+
sudo gem install
|
18
|
+
|
16
19
|
Merb/Rails
|
17
20
|
|
18
21
|
* To install as a gem:
|
19
|
-
|
20
|
-
|
22
|
+
Run the following if you haven't already:
|
23
|
+
gem sources -a http://gems.github.com
|
24
|
+
|
25
|
+
Install the gem(s):
|
26
|
+
sudo gem install jackdempsey-acts_as_commentable
|
27
|
+
|
28
|
+
add the folloowing line to your environment.rb
|
29
|
+
config.gem 'jackdempsey-acts_as_commentable', :lib => 'acts_as_commentable', :source => "http://gems.github.com"
|
30
|
+
|
21
31
|
|
22
32
|
Generate your comment model:
|
23
33
|
|
data/init.rb
CHANGED
data/lib/acts_as_commentable.rb
CHANGED
@@ -1,66 +1,2 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
# ActsAsCommentable
|
4
|
-
module Juixe
|
5
|
-
module Acts #:nodoc:
|
6
|
-
module Commentable #:nodoc:
|
7
|
-
|
8
|
-
def self.included(base)
|
9
|
-
base.extend ClassMethods
|
10
|
-
end
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
def acts_as_commentable
|
14
|
-
has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at ASC'
|
15
|
-
include Juixe::Acts::Commentable::InstanceMethods
|
16
|
-
extend Juixe::Acts::Commentable::SingletonMethods
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# This module contains class methods
|
21
|
-
module SingletonMethods
|
22
|
-
# Helper method to lookup for comments for a given object.
|
23
|
-
# This method is equivalent to obj.comments.
|
24
|
-
def find_comments_for(obj)
|
25
|
-
commentable = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s
|
26
|
-
|
27
|
-
Comment.find(:all,
|
28
|
-
:conditions => ["commentable_id = ? and commentable_type = ?", obj.id, commentable],
|
29
|
-
:order => "created_at DESC"
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Helper class method to lookup comments for
|
34
|
-
# the mixin commentable type written by a given user.
|
35
|
-
# This method is NOT equivalent to Comment.find_comments_for_user
|
36
|
-
def find_comments_by_user(user)
|
37
|
-
commentable = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s
|
38
|
-
|
39
|
-
Comment.find(:all,
|
40
|
-
:conditions => ["user_id = ? and commentable_type = ?", user.id, commentable],
|
41
|
-
:order => "created_at DESC"
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# This module contains instance methods
|
47
|
-
module InstanceMethods
|
48
|
-
# Helper method to sort comments by date
|
49
|
-
def comments_ordered_by_submitted
|
50
|
-
Comment.find(:all,
|
51
|
-
:conditions => ["commentable_id = ? and commentable_type = ?", id, self.type.name],
|
52
|
-
:order => "created_at DESC"
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Helper method that defaults the submitted time.
|
57
|
-
def add_comment(comment)
|
58
|
-
comments << comment
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
ActiveRecord::Base.send(:include, Juixe::Acts::Commentable)
|
1
|
+
require 'commentable_methods'
|
2
|
+
require 'comment_methods'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'activerecord'
|
2
|
+
|
3
|
+
# ActsAsCommentable
|
4
|
+
module Juixe
|
5
|
+
module Acts #:nodoc:
|
6
|
+
module Commentable #:nodoc:
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.extend ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def acts_as_commentable
|
14
|
+
has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at ASC'
|
15
|
+
include Juixe::Acts::Commentable::InstanceMethods
|
16
|
+
extend Juixe::Acts::Commentable::SingletonMethods
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# This module contains class methods
|
21
|
+
module SingletonMethods
|
22
|
+
# Helper method to lookup for comments for a given object.
|
23
|
+
# This method is equivalent to obj.comments.
|
24
|
+
def find_comments_for(obj)
|
25
|
+
commentable = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s
|
26
|
+
|
27
|
+
Comment.find(:all,
|
28
|
+
:conditions => ["commentable_id = ? and commentable_type = ?", obj.id, commentable],
|
29
|
+
:order => "created_at DESC"
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Helper class method to lookup comments for
|
34
|
+
# the mixin commentable type written by a given user.
|
35
|
+
# This method is NOT equivalent to Comment.find_comments_for_user
|
36
|
+
def find_comments_by_user(user)
|
37
|
+
commentable = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s
|
38
|
+
|
39
|
+
Comment.find(:all,
|
40
|
+
:conditions => ["user_id = ? and commentable_type = ?", user.id, commentable],
|
41
|
+
:order => "created_at DESC"
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# This module contains instance methods
|
47
|
+
module InstanceMethods
|
48
|
+
# Helper method to sort comments by date
|
49
|
+
def comments_ordered_by_submitted
|
50
|
+
Comment.find(:all,
|
51
|
+
:conditions => ["commentable_id = ? and commentable_type = ?", id, self.type.name],
|
52
|
+
:order => "created_at DESC"
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Helper method that defaults the submitted time.
|
57
|
+
def add_comment(comment)
|
58
|
+
comments << comment
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
ActiveRecord::Base.send(:include, Juixe::Acts::Commentable)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jackdempsey-acts_as_commentable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein
|
@@ -9,7 +9,7 @@ autorequire: acts_as_commentable
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- generators/comment/templates/create_comments.rb
|
33
33
|
- lib/acts_as_commentable.rb
|
34
34
|
- lib/comment_methods.rb
|
35
|
+
- lib/commentable_methods.rb
|
35
36
|
- tasks/acts_as_commentable_tasks.rake
|
36
37
|
- init.rb
|
37
38
|
- install.rb
|