Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

find instance method module and acts_as_ method name dynamically

Ivan Kuchinbde7c1b4e4ed
diff --git a/lib_static/open_project/acts/favorable/registry.rb b/lib_static/open_project/acts/favorable/registry.rb
index a9b53dee66c..f0c760f5cdc 100644
--- a/lib_static/open_project/acts/favorable/registry.rb
+++ b/lib_static/open_project/acts/favorable/registry.rb
@@ -43,9 +43,12 @@ module OpenProject
end
def self.add(*models)
+ instance_methods_module = module_parent.const_get(:InstanceMethods)
+ acts_as_method_name = "acts_as_#{module_parent_name.demodulize.underscore}"
+
models.each do |model|
- unless model.ancestors.include?(::OpenProject::Acts::Favorable::InstanceMethods)
- raise ArgumentError.new("Model #{model} does not include acts_as_favorable")
+ unless model.ancestors.include?(instance_methods_module)
+ raise ArgumentError.new("Model #{model} does not include #{acts_as_method_name}")
end
self.models << model
diff --git a/lib_static/open_project/acts/watchable/registry.rb b/lib_static/open_project/acts/watchable/registry.rb
index a09936f23cb..515340a2c10 100644
--- a/lib_static/open_project/acts/watchable/registry.rb
+++ b/lib_static/open_project/acts/watchable/registry.rb
@@ -43,9 +43,12 @@ module OpenProject
end
def self.add(*models)
+ instance_methods_module = module_parent.const_get(:InstanceMethods)
+ acts_as_method_name = "acts_as_#{module_parent_name.demodulize.underscore}"
+
models.each do |model|
- unless model.ancestors.include?(::OpenProject::Acts::Watchable::InstanceMethods)
- raise ArgumentError.new("Model #{model} does not include acts_as_watchable")
+ unless model.ancestors.include?(instance_methods_module)
+ raise ArgumentError.new("Model #{model} does not include #{acts_as_method_name}")
end
self.models << model