acts_as_commentable_more 1.1.0 → 1.2.0

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.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/lib/acts_as_commentable_more.rb +5 -2
  3. data/lib/{comment_methods.rb → acts_as_commentable_more/comment_methods.rb} +0 -0
  4. data/lib/acts_as_commentable_more/commentable_methods.rb +64 -0
  5. data/lib/acts_as_commentable_more/helpers/comment/callbacks_helper.rb +59 -0
  6. data/lib/acts_as_commentable_more/helpers/comment/methods_helper.rb +44 -0
  7. data/lib/acts_as_commentable_more/helpers/post/associations_helper.rb +30 -0
  8. data/lib/acts_as_commentable_more/helpers/post/methods_helper.rb +18 -0
  9. data/lib/acts_as_commentable_more/helpers/post/scopes_helper.rb +19 -0
  10. data/lib/acts_as_commentable_more/version.rb +1 -1
  11. data/lib/generators/commentable/templates/comment.rb +1 -1
  12. data/test/dummy/spec/models/letter_spec.rb +2 -1
  13. data/test/dummy/spec/models/main_model_spec.rb +5 -0
  14. data/test/dummy/spec/models/note_custom_asso_name_spec.rb +2 -1
  15. data/test/dummy/spec/models/note_spec.rb +2 -1
  16. data/test/dummy/spec/models/post_custom_asso_name_spec.rb +1 -1
  17. data/test/dummy/spec/models/post_disable_cache_spec.rb +5 -0
  18. data/test/dummy/spec/models/post_spec.rb +2 -1
  19. data/test/dummy/spec/models/topic_spec.rb +1 -1
  20. metadata +13 -165
  21. data/.coveralls.yml +0 -1
  22. data/.gitignore +0 -48
  23. data/.travis.yml +0 -22
  24. data/CHANGELOG.md +0 -12
  25. data/Gemfile +0 -40
  26. data/Gemfile.lock +0 -212
  27. data/LICENSE +0 -22
  28. data/README.md +0 -125
  29. data/acts_as_commentable_more.gemspec +0 -36
  30. data/lib/commentable_methods.rb +0 -118
  31. data/test/acts_as_commentable_more_test.rb +0 -7
  32. data/test/dummy/README.rdoc +0 -28
  33. data/test/dummy/Rakefile +0 -17
  34. data/test/dummy/app/assets/images/.keep +0 -0
  35. data/test/dummy/app/assets/javascripts/application.js +0 -13
  36. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  37. data/test/dummy/app/controllers/application_controller.rb +0 -5
  38. data/test/dummy/app/controllers/concerns/.keep +0 -0
  39. data/test/dummy/app/helpers/application_helper.rb +0 -2
  40. data/test/dummy/app/mailers/.keep +0 -0
  41. data/test/dummy/app/models/.keep +0 -0
  42. data/test/dummy/app/models/admin.rb +0 -2
  43. data/test/dummy/app/models/comment.rb +0 -17
  44. data/test/dummy/app/models/concerns/.keep +0 -0
  45. data/test/dummy/app/models/custom_comment.rb +0 -17
  46. data/test/dummy/app/models/letter.rb +0 -3
  47. data/test/dummy/app/models/note.rb +0 -3
  48. data/test/dummy/app/models/note_custom_asso_name.rb +0 -3
  49. data/test/dummy/app/models/post.rb +0 -4
  50. data/test/dummy/app/models/post_custom_asso_name.rb +0 -5
  51. data/test/dummy/app/models/topic.rb +0 -3
  52. data/test/dummy/app/models/user.rb +0 -2
  53. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  54. data/test/dummy/bin/bundle +0 -3
  55. data/test/dummy/bin/rails +0 -4
  56. data/test/dummy/bin/rake +0 -4
  57. data/test/dummy/config.ru +0 -4
  58. data/test/dummy/config/application.rb +0 -35
  59. data/test/dummy/config/boot.rb +0 -5
  60. data/test/dummy/config/database.travis.yml +0 -18
  61. data/test/dummy/config/environment.rb +0 -5
  62. data/test/dummy/config/environments/development.rb +0 -37
  63. data/test/dummy/config/environments/production.rb +0 -78
  64. data/test/dummy/config/environments/test.rb +0 -39
  65. data/test/dummy/config/initializers/assets.rb +0 -8
  66. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  67. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  68. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  69. data/test/dummy/config/initializers/inflections.rb +0 -16
  70. data/test/dummy/config/initializers/mime_types.rb +0 -4
  71. data/test/dummy/config/initializers/session_store.rb +0 -3
  72. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  73. data/test/dummy/config/locales/en.yml +0 -23
  74. data/test/dummy/config/routes.rb +0 -56
  75. data/test/dummy/config/secrets.yml +0 -22
  76. data/test/dummy/db/migrate/20150113045806_create_posts.rb +0 -9
  77. data/test/dummy/db/migrate/20150113045817_create_admins.rb +0 -9
  78. data/test/dummy/db/migrate/20150113045831_create_users.rb +0 -9
  79. data/test/dummy/db/migrate/20150113065948_create_notes.rb +0 -9
  80. data/test/dummy/db/migrate/20150113074249_create_topics.rb +0 -9
  81. data/test/dummy/db/migrate/20150114052120_create_letters.rb +0 -9
  82. data/test/dummy/db/migrate/20150114100411_create_comments.rb +0 -18
  83. data/test/dummy/db/migrate/20150114100422_create_custom_comments.rb +0 -18
  84. data/test/dummy/db/migrate/20150115094241_create_post_custom_asso_names.rb +0 -9
  85. data/test/dummy/db/migrate/20150115100013_create_note_custom_asso_names.rb +0 -9
  86. data/test/dummy/lib/assets/.keep +0 -0
  87. data/test/dummy/log/.keep +0 -0
  88. data/test/dummy/public/404.html +0 -67
  89. data/test/dummy/public/422.html +0 -67
  90. data/test/dummy/public/500.html +0 -66
  91. data/test/dummy/public/favicon.ico +0 -0
  92. data/test/dummy/spec/acts_as_commentable_more_spec.rb +0 -275
  93. data/test/dummy/spec/factories/admins.rb +0 -7
  94. data/test/dummy/spec/factories/comments.rb +0 -7
  95. data/test/dummy/spec/factories/custom_comments.rb +0 -7
  96. data/test/dummy/spec/factories/letters.rb +0 -7
  97. data/test/dummy/spec/factories/note_custom_asso_names.rb +0 -7
  98. data/test/dummy/spec/factories/notes.rb +0 -7
  99. data/test/dummy/spec/factories/post_custom_asso_names.rb +0 -7
  100. data/test/dummy/spec/factories/posts.rb +0 -7
  101. data/test/dummy/spec/factories/topics.rb +0 -7
  102. data/test/dummy/spec/factories/users.rb +0 -7
  103. data/test/dummy/spec/rails_helper.rb +0 -61
  104. data/test/dummy/spec/spec_helper.rb +0 -85
  105. data/test/test_helper.rb +0 -16
@@ -1,36 +0,0 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
-
3
- # Maintain your gem's version:
4
- require "acts_as_commentable_more/version"
5
-
6
- # Describe your gem and declare its dependencies:
7
- Gem::Specification.new do |s|
8
- s.name = "acts_as_commentable_more"
9
- s.version = ActsAsCommentableMore::VERSION
10
- s.authors = ["piya23300"]
11
- s.email = ["piya23300@gmail.com"]
12
- s.homepage = "https://github.com/piya23300/acts_as_commentable_more"
13
- s.summary = "gem that provides comment functionality."
14
- s.description = "gem that provides comment functionality."
15
- s.license = "MIT"
16
-
17
- s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
18
- s.test_files = Dir["test/**/*"]
19
-
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
- s.require_paths = ["lib"]
24
-
25
- s.autorequire = %q{acts_as_commentable_more}
26
-
27
- s.add_development_dependency 'rake'
28
- s.add_development_dependency 'rspec'
29
-
30
-
31
- s.add_dependency "rails", "~> 4.1.8"
32
-
33
- s.add_development_dependency "pg"
34
- # s.add_development_dependency "acts_as_commentable"
35
-
36
- end
@@ -1,118 +0,0 @@
1
- # ActsAsCommentable
2
- module Happio
3
- module Acts #:nodoc:
4
- module Commentable #:nodoc:
5
- extend ActiveSupport::Concern
6
-
7
- module HelperMethods
8
- private
9
- def define_role_based_inflection(role, association_base_name, join_options)
10
- association_name = "#{role.to_s}_#{association_base_name.to_s}"
11
- send("define_role_based_inflection_#{Rails.version.first}", role, association_name,join_options)
12
- end
13
-
14
- def define_role_based_inflection_3(role, association_name, join_options)
15
- has_many "#{association_name.to_s}".to_sym,
16
- has_many_options(role, join_options).merge(:conditions => { role: role.to_s })
17
- end
18
-
19
- def define_role_based_inflection_4(role, association_name, join_options)
20
- has_many "#{association_name.to_s}".to_sym,
21
- -> { where(role: role.to_s) },
22
- has_many_options(role, join_options)
23
- define_create_role_comments(association_name)
24
- end
25
-
26
- def has_many_options(role, join_options)
27
- { :before_add => Proc.new { |x, c| c.role = role.to_s } }.merge(join_options)
28
- end
29
-
30
- def define_create_role_comments(association_name)
31
- class_eval %{
32
- def creates_#{association_name.to_s.pluralize}(attributes = nil)
33
- #{association_name.to_s}.create(attributes)
34
- end
35
- }
36
- end
37
-
38
- end
39
-
40
- module ClassMethods
41
- include HelperMethods
42
-
43
- def acts_as_commentable(types: [], options: {}, as: nil)
44
- mattr_accessor :comment_roles
45
-
46
- default_options = {as: :commentable, dependent: :destroy, class_name: 'Comment'}
47
- default_as = :comments
48
- default_roles = [default_as.to_s.singularize.to_sym]
49
-
50
- types = types.flatten.compact.map(&:to_sym)
51
-
52
-
53
- association_options = default_options.merge(options.compact)
54
- self.comment_roles = types.present? ? types : default_roles
55
- association_base_name = (as || default_as).to_s.pluralize
56
-
57
- if comment_roles == [default_as.to_s.singularize.to_sym]
58
- has_many association_base_name.to_sym, has_many_options(association_base_name.singularize, association_options)
59
- define_create_role_comments(association_base_name)
60
- else
61
- comment_roles.each do |role|
62
- define_role_based_inflection(role, association_base_name, association_options)
63
- end
64
-
65
- association_class = association_options[:class_name].classify.constantize
66
-
67
- class_eval %{
68
- def all_#{association_base_name.to_s}
69
- #{association_class}
70
- .where(
71
- #{association_options[:as].to_s + '_id'}: self.id,
72
- #{association_options[:as].to_s + '_type'}: self.class.base_class.name
73
- ).order(created_at: :desc)
74
- end
75
- }
76
-
77
- association_class.class_eval %{
78
- private
79
-
80
- def can_change_role?(role)
81
- commentable_object = #{association_options[:as]}
82
- limit_role = commentable_object.class.comment_roles
83
- # p limit_role
84
- # p role
85
- limit_role.include?(role.to_sym)
86
- end
87
-
88
- }
89
-
90
- comment_roles.each do |role|
91
- association_class.class_eval %{
92
- def is_#{role}?
93
- role == "#{role.to_s}"
94
- end
95
-
96
- def to_#{role}
97
- raise TypeError, "Can not change to " + role.to_s unless can_change_role?("#{role.to_s}")
98
- self.role = "#{role.to_s}"
99
- end
100
-
101
- def to_#{role}!
102
- to_#{role}
103
- self.save
104
- end
105
-
106
- }
107
- end
108
- end
109
-
110
- end
111
-
112
- end
113
-
114
- end
115
- end
116
- end
117
-
118
- ActiveRecord::Base.send(:include, Happio::Acts::Commentable)
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActsAsCommentableMoreTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, ActsAsCommentableMore
6
- end
7
- end
@@ -1,28 +0,0 @@
1
- == README
2
-
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.
@@ -1,17 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- # require "bundler/gem_tasks"
5
- require "rspec/core/rake_task"
6
-
7
- RSpec::Core::RakeTask.new
8
-
9
- task :default => :spec
10
- task :test => :spec
11
-
12
- require 'bundler/gem_helper'
13
- Bundler::GemHelper.install_tasks :name => "acts_as_commentable_more", :dir => "../.."
14
-
15
- require File.expand_path('../config/application', __FILE__)
16
-
17
- Rails.application.load_tasks
File without changes
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,5 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
5
- end
File without changes
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
File without changes
File without changes
@@ -1,2 +0,0 @@
1
- class Admin < ActiveRecord::Base
2
- end
@@ -1,17 +0,0 @@
1
-
2
- class Comment < ActiveRecord::Base
3
- ###################################################################
4
- ### To implement commentable add the following line to your model
5
- ### acts_as_commentable types: [:hide, :show], options: { class_name: 'Comment', as: :commentable }
6
-
7
- ### types is an array of possible comment type
8
- ### for example if you have public and private comment
9
- ### your types would be [:public, :private]
10
-
11
- include ActsAsCommentableMore::Finders
12
-
13
- belongs_to :commentable, :polymorphic => true
14
- belongs_to :user, polymorphic: true
15
-
16
- ###################################################################
17
- end
File without changes
@@ -1,17 +0,0 @@
1
-
2
- class CustomComment < ActiveRecord::Base
3
- ###################################################################
4
- ### To implement commentable add the following line to your model
5
- ### acts_as_commentable types: [:hide, :show], options: { class_name: 'CustomComment', as: :custom_commentable }
6
-
7
- ### types is an array of possible comment type
8
- ### for example if you have public and private comment
9
- ### your types would be [:public, :private]
10
-
11
- include ActsAsCommentableMore::Finders
12
-
13
- belongs_to :custom_commentable, :polymorphic => true
14
- belongs_to :user, polymorphic: true
15
-
16
- ###################################################################
17
- end
@@ -1,3 +0,0 @@
1
- class Letter < ActiveRecord::Base
2
- acts_as_commentable types: [:hide, :show], options: { class_name: 'CustomComment', as: :custom_commentable }
3
- end
@@ -1,3 +0,0 @@
1
- class Note < ActiveRecord::Base
2
- acts_as_commentable types: [:private, :public]
3
- end
@@ -1,3 +0,0 @@
1
- class NoteCustomAssoName < ActiveRecord::Base
2
- acts_as_commentable types: [:private, :public], as: :custom_comments
3
- end
@@ -1,4 +0,0 @@
1
- class Post < ActiveRecord::Base
2
- acts_as_commentable
3
- end
4
-
@@ -1,5 +0,0 @@
1
- class PostCustomAssoName < ActiveRecord::Base
2
- acts_as_commentable as: :custom_comments
3
-
4
- end
5
-
@@ -1,3 +0,0 @@
1
- class Topic < ActiveRecord::Base
2
- acts_as_commentable options: { class_name: 'CustomComment', as: :custom_commentable }
3
- end
@@ -1,2 +0,0 @@
1
- class User < ActiveRecord::Base
2
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- load Gem.bin_path('bundler', 'bundle')
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require_relative '../config/boot'
3
- require 'rake'
4
- Rake.application.run
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run Rails.application
@@ -1,35 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require 'rails/all'
4
-
5
- Bundler.require(*Rails.groups)
6
- require "acts_as_commentable_more"
7
-
8
- module Dummy
9
- class Application < Rails::Application
10
- # Settings in config/environments/* take precedence over those specified here.
11
- # Application configuration should go into files in config/initializers
12
- # -- all .rb files in that directory are automatically loaded.
13
-
14
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
- # config.time_zone = 'Central Time (US & Canada)'
17
-
18
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
- # config.i18n.default_locale = :de
21
- config.generators do |g|
22
- g.test_framework :rspec,
23
- :fixtures => true,
24
- :view_specs => false,
25
- :helper_specs => false,
26
- :routing_specs => false,
27
- :controller_specs => false,
28
- :request_specs => true,
29
- :model_specs => false
30
- g.fixture_replacement :factory_girl,
31
- :dir => "spec/factories"
32
- end
33
- end
34
- end
35
-
@@ -1,5 +0,0 @@
1
- # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,18 +0,0 @@
1
- defaults: &defaults
2
- adapter: postgresql
3
- encoding: unicode
4
- database: acts_at_commentable_<%= Rails.env %>
5
- pool: 5
6
- username: postgres
7
- password:
8
- template: template0
9
- host: localhost
10
-
11
- development:
12
- <<: *defaults
13
-
14
- test:
15
- <<: *defaults
16
-
17
- production:
18
- <<: *defaults
@@ -1,5 +0,0 @@
1
- # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the Rails application.
5
- Rails.application.initialize!