From 29c20826057e7c4c4aab670eb1221fffe19a933c Mon Sep 17 00:00:00 2001 From: "vilet.yy" Date: Fri, 14 May 2021 18:12:49 +0800 Subject: [PATCH] fix:some bug --- acts_as_able.gemspec | 5 ++--- init.rb | 2 ++ lib/{acts_as_followable.rb => acts_as_able.rb} | 12 ++++++++++-- lib/acts_as_able/unlikable.rb | 2 +- lib/acts_as_able/viewable.rb | 4 ++-- lib/acts_as_able/viewer.rb | 2 +- lib/acts_as_unlikeable.rb | 15 --------------- lib/acts_as_viewable.rb | 15 --------------- ...enerator.rb => acts_as_unlikable_generator.rb} | 2 +- lib/generators/acts_as_viewable_generator.rb | 2 +- lib/generators/templates/view_migration.rb | 2 +- 11 files changed, 21 insertions(+), 42 deletions(-) create mode 100644 init.rb rename lib/{acts_as_followable.rb => acts_as_able.rb} (54%) delete mode 100644 lib/acts_as_unlikeable.rb delete mode 100644 lib/acts_as_viewable.rb rename lib/generators/{acts_as_unlikeable_generator.rb => acts_as_unlikable_generator.rb} (82%) diff --git a/acts_as_able.gemspec b/acts_as_able.gemspec index 13dc556..109d108 100644 --- a/acts_as_able.gemspec +++ b/acts_as_able.gemspec @@ -1,6 +1,5 @@ # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +$:.push File.expand_path("../lib", __FILE__) require 'acts_as_able/version' Gem::Specification.new do |spec| @@ -30,5 +29,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.16" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "rails", "~> 5.0" + spec.add_development_dependency "rails", "~> 6.0" end diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..3fa082e --- /dev/null +++ b/init.rb @@ -0,0 +1,2 @@ +$:.unshift "#{File.dirname(__FILE__)}/lib" +require "acts_as_able" diff --git a/lib/acts_as_followable.rb b/lib/acts_as_able.rb similarity index 54% rename from lib/acts_as_followable.rb rename to lib/acts_as_able.rb index c157555..45f2cd8 100644 --- a/lib/acts_as_followable.rb +++ b/lib/acts_as_able.rb @@ -1,15 +1,23 @@ require "acts_as_able/version" -module ActsAsFollowable +module ActsAsAble extend ActiveSupport::Autoload autoload :AbleExt, 'acts_as_able/able_ext' autoload :Followable, 'acts_as_able/followable' autoload :Follower, 'acts_as_able/follower' + autoload :Unlikable, 'acts_as_able/unlikable' + autoload :Unliker, 'acts_as_able/unliker' + autoload :Viewable, 'acts_as_able/viewable' + autoload :Viewer, 'acts_as_able/viewer' # require 'acts_as_followable/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3 ActiveSupport.on_load(:active_record) do include ActsAsAble::Followable include ActsAsAble::Follower + include ActsAsAble::Unlikable + include ActsAsAble::Unliker + include ActsAsAble::Viewable + include ActsAsAble::Viewer end -end +end \ No newline at end of file diff --git a/lib/acts_as_able/unlikable.rb b/lib/acts_as_able/unlikable.rb index 8cf969d..eafbd53 100644 --- a/lib/acts_as_able/unlikable.rb +++ b/lib/acts_as_able/unlikable.rb @@ -9,7 +9,7 @@ module ActsAsAble module ClassMethods # Those call this method has the ability to be unlike by others def acts_as_unlikable - include ActAsAble::AbleExt + include ActsAsAble::AbleExt has_many :unlikers, as: :unlikable, dependent: :destroy, class_name: 'Unlike' end end diff --git a/lib/acts_as_able/viewable.rb b/lib/acts_as_able/viewable.rb index 6b4e7ad..26e369c 100644 --- a/lib/acts_as_able/viewable.rb +++ b/lib/acts_as_able/viewable.rb @@ -7,9 +7,9 @@ module ActsAsAble end module ClassMethods - # Those call this method has the ability to be unlike by others + # Those call this method has the ability to be unlike by others def acts_as_viewable - include ActAsAble::AbleExt + include ActsAsAble::AbleExt has_many :viewers, as: :viewable, dependent: :destroy, class_name: 'View' end end diff --git a/lib/acts_as_able/viewer.rb b/lib/acts_as_able/viewer.rb index 48c46d4..40d3f99 100644 --- a/lib/acts_as_able/viewer.rb +++ b/lib/acts_as_able/viewer.rb @@ -22,7 +22,7 @@ module ActsAsAble # 是否不喜欢某对象 def view?(obj) - !unlike_by(obj).blank? + !view_by(obj).blank? end private diff --git a/lib/acts_as_unlikeable.rb b/lib/acts_as_unlikeable.rb deleted file mode 100644 index 006b33e..0000000 --- a/lib/acts_as_unlikeable.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "acts_as_able/version" - -module ActsAsUnlikeable - extend ActiveSupport::Autoload - autoload :AbleExt, 'acts_as_able/able_ext' - autoload :Unlikable, 'acts_as_able/unlikable' - autoload :Unliker, 'acts_as_able/unliker' - - # require 'acts_as_followable/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3 - ActiveSupport.on_load(:active_record) do - include ActsAsAble::Unlikable - include ActsAsAble::Unliker - end - -end diff --git a/lib/acts_as_viewable.rb b/lib/acts_as_viewable.rb deleted file mode 100644 index 06f0e33..0000000 --- a/lib/acts_as_viewable.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "acts_as_able/version" - -module ActsAsViewable - extend ActiveSupport::Autoload - autoload :AbleExt, 'acts_as_able/able_ext' - autoload :Viewable, 'acts_as_able/viewable' - autoload :Viewer, 'acts_as_able/viewer' - - # require 'acts_as_followable/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3 - ActiveSupport.on_load(:active_record) do - include ActsAsAble::Viewable - include ActsAsAble::Viewer - end - -end diff --git a/lib/generators/acts_as_unlikeable_generator.rb b/lib/generators/acts_as_unlikable_generator.rb similarity index 82% rename from lib/generators/acts_as_unlikeable_generator.rb rename to lib/generators/acts_as_unlikable_generator.rb index b47551a..a34ceb7 100644 --- a/lib/generators/acts_as_unlikeable_generator.rb +++ b/lib/generators/acts_as_unlikable_generator.rb @@ -1,6 +1,6 @@ require 'generators/acts_as_able_generator' -class ActsAsUnlikeableGenerator < ActsAsAbleGenerator +class ActsAsUnlikableGenerator < ActsAsAbleGenerator def create_migration_file migration_template 'unlike_migration.rb', 'db/migrate/acts_as_unlikable_migration.rb' end diff --git a/lib/generators/acts_as_viewable_generator.rb b/lib/generators/acts_as_viewable_generator.rb index b9179fe..46988c6 100644 --- a/lib/generators/acts_as_viewable_generator.rb +++ b/lib/generators/acts_as_viewable_generator.rb @@ -1,6 +1,6 @@ require 'generators/acts_as_able_generator' -class ActsAsUnlikeableGenerator < ActsAsAbleGenerator +class ActsAsViewableGenerator < ActsAsAbleGenerator def create_migration_file migration_template 'view_migration.rb', 'db/migrate/acts_as_viewable_migration.rb' end diff --git a/lib/generators/templates/view_migration.rb b/lib/generators/templates/view_migration.rb index b2a211c..4136749 100644 --- a/lib/generators/templates/view_migration.rb +++ b/lib/generators/templates/view_migration.rb @@ -1,4 +1,4 @@ -class ActsAsUnlikableMigration < ActiveRecord::Migration[5.0] +class ActsAsViewableMigration < ActiveRecord::Migration[5.0] def self.up create_table :views, force: true do |t| t.references :viewable, polymorphic: true, null: false