Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades for Ruby 3.0.5. #1

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions acts_as_commentable.gemspec
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{acts_as_commentable}
s.version = "4.0.2"
s.name = 'acts_as_commentable'
s.version = '4.0.3'

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein"]
s.autorequire = %q{acts_as_commentable}
s.description = %q{Plugin/gem that provides comment functionality}
s.email = %q{unknown@juixe.com}
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE"]
s.files = ["MIT-LICENSE", "README.rdoc", "lib/acts_as_commentable.rb", "lib/comment_methods.rb", "lib/commentable_methods.rb", "lib/generators", "lib/generators/comment", "lib/generators/comment/comment_generator.rb", "lib/generators/comment/templates", "lib/generators/comment/templates/comment.rb", "lib/generators/comment/templates/create_comments.rb", "lib/generators/comment/USAGE", "init.rb", "install.rb"]
s.homepage = %q{http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.6}
s.summary = %q{Plugin/gem that provides comment functionality}
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
s.authors = ['Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein']
s.autorequire = 'acts_as_commentable'
s.description = 'Plugin/gem that provides comment functionality'
s.email = 'unknown@juixe.com'
s.extra_rdoc_files = ['README.rdoc', 'MIT-LICENSE']
s.files = ['MIT-LICENSE', 'README.rdoc', 'lib/acts_as_commentable.rb', 'lib/comment_methods.rb',
'lib/commentable_methods.rb', 'lib/generators', 'lib/generators/comment', 'lib/generators/comment/comment_generator.rb', 'lib/generators/comment/templates', 'lib/generators/comment/templates/comment.rb', 'lib/generators/comment/templates/create_comments.rb', 'lib/generators/comment/USAGE', 'init.rb', 'install.rb']
s.homepage = 'http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/'
s.require_paths = ['lib']
s.rubygems_version = '1.3.6'
s.summary = 'Plugin/gem that provides comment functionality'
s.license = 'MIT'

if s.respond_to? :specification_version then
if s.respond_to? :specification_version
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
else
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0')
end
else
end
end
52 changes: 28 additions & 24 deletions lib/commentable_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,43 @@

# ActsAsCommentable
module Juixe
module Acts #:nodoc:
module Commentable #:nodoc:

module Acts # :nodoc:
module Commentable # :nodoc:
def self.included(base)
base.extend ClassMethods
end

module HelperMethods
private

def define_role_based_inflection(role)
send("define_role_based_inflection_#{Rails.version.first}", role)
end

def define_role_based_inflection_3(role)
has_many "#{role.to_s}_comments".to_sym,
has_many_options(role).merge(:conditions => { role: role.to_s })
has_many "#{role}_comments".to_sym,
**has_many_options(role).merge(conditions: { role: role.to_s })
end

def define_role_based_inflection_4(role)
has_many "#{role.to_s}_comments".to_sym,
has_many "#{role}_comments".to_sym,
-> { where(role: role.to_s) },
has_many_options(role)
**has_many_options(role)
end

def has_many_options(role)
{:class_name => "Comment",
:as => :commentable,
:dependent => :destroy,
:before_add => Proc.new { |x, c| c.role = role.to_s }
}
{ class_name: 'Comment',
as: :commentable,
dependent: :destroy,
before_add: proc { |_x, c| c.role = role.to_s } }
end
end

module ClassMethods
include HelperMethods

def acts_as_commentable(*args)
options = args.to_a.flatten.compact.partition{ |opt| opt.kind_of? Hash }
options = args.to_a.flatten.compact.partition { |opt| opt.is_a? Hash }
comment_roles = options.last.blank? ? nil : options.last.flatten.compact.map(&:to_sym)

join_options = options.first.blank? ? [{}] : options.first
Expand All @@ -52,41 +51,46 @@ def acts_as_commentable(*args)
if !comment_roles.blank?
comment_roles.each do |role|
define_role_based_inflection(role)
accepts_nested_attributes_for "#{role.to_s}_comments".to_sym, allow_destroy: true, reject_if: proc { |attributes| attributes['title'].blank? && attributes['comment'].blank? }
accepts_nested_attributes_for "#{role}_comments".to_sym, allow_destroy: true, reject_if: proc { |attributes|
attributes['title'].blank? && attributes['comment'].blank?
}
end
has_many :all_comments, { :as => :commentable, :dependent => :destroy, class_name: 'Comment' }.merge(join_options)
has_many :all_comments,
**{ as: :commentable, dependent: :destroy, class_name: 'Comment' }.merge(join_options)
else
has_many :comments, {:as => :commentable, :dependent => :destroy}.merge(join_options)
accepts_nested_attributes_for :comments, allow_destroy: true, reject_if: proc { |attributes| attributes['title'].blank? && attributes['comment'].blank? }
has_many :comments, **{ as: :commentable, dependent: :destroy }.merge(join_options)
accepts_nested_attributes_for :comments, allow_destroy: true, reject_if: proc { |attributes|
attributes['title'].blank? && attributes['comment'].blank?
}
end

comment_types.each do |role|
method_name = (role == :comments ? "comments" : "#{role.to_s}_comments").to_s
method_name = (role == :comments ? 'comments' : "#{role}_comments").to_s
class_eval %{
def self.find_#{method_name}_for(obj)
commentable = self.base_class.name
Comment.find_comments_for_commentable(commentable, obj.id, "#{role.to_s}")
Comment.find_comments_for_commentable(commentable, obj.id, "#{role}")
end

def self.find_#{method_name}_by_user(user)
commentable = self.base_class.name
Comment.where(["user_id = ? and commentable_type = ? and role = ?", user.id, commentable, "#{role.to_s}"]).order("created_at DESC")
Comment.where(["user_id = ? and commentable_type = ? and role = ?", user.id, commentable, "#{role}"]).order("created_at DESC")
end

def #{method_name}_ordered_by_submitted
Comment.find_comments_for_commentable(self.class.name, id, "#{role.to_s}").order("created_at")
Comment.find_comments_for_commentable(self.class.name, id, "#{role}").order("created_at")
end

def add_#{method_name.singularize}(comment)
comment.role = "#{role.to_s}"
comment.role = "#{role}"
#{method_name} << comment
end
}
}, __FILE__, __LINE__ - 19
end
end
end
end
end
end

ActiveRecord::Base.send(:include, Juixe::Acts::Commentable)
ActiveRecord::Base.include Juixe::Acts::Commentable