acts_as_commentable 2.0.1 → 2.0.2

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.
@@ -0,0 +1,13 @@
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
@@ -12,4 +12,5 @@ class Comment < ActiveRecord::Base
12
12
 
13
13
  # NOTE: Comments belong to a user
14
14
  belongs_to :user
15
+
15
16
  end
@@ -9,21 +9,28 @@ module ActsAsCommentable
9
9
 
10
10
  def self.included(comment_model)
11
11
  comment_model.extend Finders
12
- comment_model.scope :in_order, comment_model.order('created_at ASC')
13
- comment_model.scope :recent, comment_model.order('created_at DESC')
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}}
14
15
  end
15
16
 
16
17
  module Finders
17
18
  # Helper class method to lookup all comments assigned
18
19
  # to all commentable types for a given user.
19
20
  def find_comments_by_user(user)
20
- where(["user_id = ?", user.id]).order("created_at DESC")
21
+ find(:all,
22
+ :conditions => ["user_id = ?", user.id],
23
+ :order => "created_at DESC"
24
+ )
21
25
  end
22
26
 
23
27
  # Helper class method to look up all comments for
24
28
  # commentable class name and commentable id.
25
29
  def find_comments_for_commentable(commentable_str, commentable_id)
26
- where(["commentable_type = ? and commentable_id = ?", commentable_str, commentable_id]).order("created_at DESC")
30
+ find(:all,
31
+ :conditions => ["commentable_type = ? and commentable_id = ?", commentable_str, commentable_id],
32
+ :order => "created_at DESC"
33
+ )
27
34
  end
28
35
 
29
36
  # Helper class method to look up a commentable object
@@ -33,4 +40,4 @@ module ActsAsCommentable
33
40
  end
34
41
  end
35
42
  end
36
- end
43
+ end
@@ -1,4 +1,4 @@
1
- require 'active_record'
1
+ require 'activerecord'
2
2
 
3
3
  # ActsAsCommentable
4
4
  module Juixe
@@ -23,7 +23,11 @@ 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
- Comment.find_comments_for_commentable(commentable, obj.id)
26
+
27
+ Comment.find(:all,
28
+ :conditions => ["commentable_id = ? and commentable_type = ?", obj.id, commentable],
29
+ :order => "created_at DESC"
30
+ )
27
31
  end
28
32
 
29
33
  # Helper class method to lookup comments for
@@ -31,7 +35,11 @@ module Juixe
31
35
  # This method is NOT equivalent to Comment.find_comments_for_user
32
36
  def find_comments_by_user(user)
33
37
  commentable = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s
34
- Comment.where(["user_id = ? and commentable_type = ?", user.id, commentable]).order("created_at DESC")
38
+
39
+ Comment.find(:all,
40
+ :conditions => ["user_id = ? and commentable_type = ?", user.id, commentable],
41
+ :order => "created_at DESC"
42
+ )
35
43
  end
36
44
  end
37
45
 
@@ -39,7 +47,10 @@ module Juixe
39
47
  module InstanceMethods
40
48
  # Helper method to sort comments by date
41
49
  def comments_ordered_by_submitted
42
- Comment.find_comments_for_commentable(self.class.name, id)
50
+ Comment.find(:all,
51
+ :conditions => ["commentable_id = ? and commentable_type = ?", id, self.class.name],
52
+ :order => "created_at DESC"
53
+ )
43
54
  end
44
55
 
45
56
  # Helper method that defaults the submitted time.
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_commentable
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 0
8
- - 1
9
- version: 2.0.1
4
+ version: 2.0.2
10
5
  platform: ruby
11
6
  authors:
12
7
  - Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein
@@ -14,7 +9,7 @@ autorequire: acts_as_commentable
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-09-05 00:00:00 -04:00
12
+ date: 2009-07-01 00:00:00 -04:00
18
13
  default_executable:
19
14
  dependencies: []
20
15
 
@@ -30,13 +25,12 @@ extra_rdoc_files:
30
25
  files:
31
26
  - MIT-LICENSE
32
27
  - README
28
+ - generators/comment/comment_generator.rb
29
+ - generators/comment/templates/comment.rb
30
+ - generators/comment/templates/create_comments.rb
33
31
  - lib/acts_as_commentable.rb
34
32
  - lib/comment_methods.rb
35
33
  - lib/commentable_methods.rb
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
34
  - tasks/acts_as_commentable_tasks.rake
41
35
  - init.rb
42
36
  - install.rb
@@ -50,25 +44,21 @@ rdoc_options: []
50
44
  require_paths:
51
45
  - lib
52
46
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
47
  requirements:
55
48
  - - ">="
56
49
  - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
50
  version: "0"
51
+ version:
60
52
  required_rubygems_version: !ruby/object:Gem::Requirement
61
- none: false
62
53
  requirements:
63
54
  - - ">="
64
55
  - !ruby/object:Gem::Version
65
- segments:
66
- - 0
67
56
  version: "0"
57
+ version:
68
58
  requirements: []
69
59
 
70
60
  rubyforge_project:
71
- rubygems_version: 1.3.7
61
+ rubygems_version: 1.3.5
72
62
  signing_key:
73
63
  specification_version: 3
74
64
  summary: Plugin/gem that provides comment functionality
@@ -1,6 +0,0 @@
1
- Description:
2
- Copies comment.rb to app/models/.
3
- Copies create_comment.rb to db/migrate
4
-
5
- Examples:
6
- `rails generate comment`
@@ -1,18 +0,0 @@
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