acts_as_commentable 2.1.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,28 +9,21 @@ module ActsAsCommentable
9
9
 
10
10
  def self.included(comment_model)
11
11
  comment_model.extend Finders
12
- comment_model.named_scope :in_order, {:order => 'created_at ASC'}
13
- comment_model.named_scope :recent, {:order => "created_at DESC"}
14
- comment_model.named_scope :limit, lambda {|limit| {:limit => limit}}
12
+ comment_model.scope :in_order, comment_model.order('created_at ASC')
13
+ comment_model.scope :recent, comment_model.order('created_at DESC')
15
14
  end
16
15
 
17
16
  module Finders
18
17
  # Helper class method to lookup all comments assigned
19
18
  # to all commentable types for a given user.
20
19
  def find_comments_by_user(user)
21
- find(:all,
22
- :conditions => ["user_id = ?", user.id],
23
- :order => "created_at DESC"
24
- )
20
+ where(["user_id = ?", user.id]).order("created_at DESC")
25
21
  end
26
22
 
27
23
  # Helper class method to look up all comments for
28
24
  # commentable class name and commentable id.
29
25
  def find_comments_for_commentable(commentable_str, commentable_id)
30
- find(:all,
31
- :conditions => ["commentable_type = ? and commentable_id = ?", commentable_str, commentable_id],
32
- :order => "created_at DESC"
33
- )
26
+ where(["commentable_type = ? and commentable_id = ?", commentable_str, commentable_id]).order("created_at DESC")
34
27
  end
35
28
 
36
29
  # Helper class method to look up a commentable object
@@ -40,4 +33,4 @@ module ActsAsCommentable
40
33
  end
41
34
  end
42
35
  end
43
- end
36
+ end
@@ -10,8 +10,8 @@ module Juixe
10
10
  end
11
11
 
12
12
  module ClassMethods
13
- def acts_as_commentable(options={})
14
- has_many :comments, {:as => :commentable, :dependent => :destroy}.merge(options)
13
+ def acts_as_commentable
14
+ has_many :comments, :as => :commentable, :dependent => :destroy
15
15
  include Juixe::Acts::Commentable::InstanceMethods
16
16
  extend Juixe::Acts::Commentable::SingletonMethods
17
17
  end
@@ -23,11 +23,7 @@ module Juixe
23
23
  # This method is equivalent to obj.comments.
24
24
  def find_comments_for(obj)
25
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
- )
26
+ Comment.find_comments_for_commentable(commentable, obj.id)
31
27
  end
32
28
 
33
29
  # Helper class method to lookup comments for
@@ -35,11 +31,7 @@ module Juixe
35
31
  # This method is NOT equivalent to Comment.find_comments_for_user
36
32
  def find_comments_by_user(user)
37
33
  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
- )
34
+ Comment.where(["user_id = ? and commentable_type = ?", user.id, commentable]).order("created_at DESC")
43
35
  end
44
36
  end
45
37
 
@@ -47,10 +39,7 @@ module Juixe
47
39
  module InstanceMethods
48
40
  # Helper method to sort comments by date
49
41
  def comments_ordered_by_submitted
50
- Comment.find(:all,
51
- :conditions => ["commentable_id = ? and commentable_type = ?", id, self.class.name],
52
- :order => "created_at DESC"
53
- )
42
+ Comment.find_comments_for_commentable(self.class.name, id)
54
43
  end
55
44
 
56
45
  # Helper method that defaults the submitted time.
@@ -0,0 +1,6 @@
1
+ Description:
2
+ Copies comment.rb to app/models/.
3
+ Copies create_comment.rb to db/migrate
4
+
5
+ Examples:
6
+ `rails generate comment`
@@ -0,0 +1,18 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class CommentGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ def self.source_root
7
+ @_acts_as_commentable_source_root ||= File.expand_path("../templates", __FILE__)
8
+ end
9
+
10
+ def self.next_migration_number(path)
11
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
12
+ end
13
+
14
+ def create_model_file
15
+ template "comment.rb", "app/models/comment.rb"
16
+ migration_template "create_comments.rb", "db/migrate/create_comments.rb"
17
+ end
18
+ end
@@ -12,5 +12,4 @@ class Comment < ActiveRecord::Base
12
12
 
13
13
  # NOTE: Comments belong to a user
14
14
  belongs_to :user
15
-
16
15
  end
metadata CHANGED
@@ -3,10 +3,10 @@ name: acts_as_commentable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 2
7
- - 1
8
- - 1
9
- version: 2.1.1
6
+ - 3
7
+ - 0
8
+ - 0
9
+ version: 3.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein
@@ -14,7 +14,7 @@ autorequire: acts_as_commentable
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-07 00:00:00 -04:00
17
+ date: 2010-03-07 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -30,16 +30,17 @@ extra_rdoc_files:
30
30
  files:
31
31
  - MIT-LICENSE
32
32
  - README
33
- - generators/comment/comment_generator.rb
34
- - generators/comment/templates/comment.rb
35
- - generators/comment/templates/create_comments.rb
36
33
  - lib/acts_as_commentable.rb
37
34
  - lib/comment_methods.rb
38
35
  - lib/commentable_methods.rb
39
- - lib/tasks/acts_as_commentable_tasks.rake
36
+ - lib/generators/comment/comment_generator.rb
37
+ - lib/generators/comment/templates/comment.rb
38
+ - lib/generators/comment/templates/create_comments.rb
39
+ - lib/generators/comment/USEGA
40
+ - tasks/acts_as_commentable_tasks.rake
40
41
  - init.rb
41
42
  - install.rb
42
- has_rdoc: false
43
+ has_rdoc: true
43
44
  homepage: http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
44
45
  licenses: []
45
46
 
@@ -49,7 +50,6 @@ rdoc_options: []
49
50
  require_paths:
50
51
  - lib
51
52
  required_ruby_version: !ruby/object:Gem::Requirement
52
- none: false
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
@@ -57,7 +57,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
57
  - 0
58
58
  version: "0"
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
60
  requirements:
62
61
  - - ">="
63
62
  - !ruby/object:Gem::Version
@@ -67,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
66
  requirements: []
68
67
 
69
68
  rubyforge_project:
70
- rubygems_version: 1.3.7
69
+ rubygems_version: 1.3.6
71
70
  signing_key:
72
71
  specification_version: 3
73
72
  summary: Plugin/gem that provides comment functionality
@@ -1,13 +0,0 @@
1
- class CommentGenerator < Rails::Generator::Base
2
- def manifest
3
- record do |m|
4
- m.directory 'app/models'
5
- m.file 'comment.rb', 'app/models/comment.rb'
6
- m.migration_template "create_comments.rb", "db/migrate"
7
- end
8
- end
9
- # ick what a hack.
10
- def file_name
11
- "create_comments"
12
- end
13
- end