Skip to content
Snippets Groups Projects
Unverified Commit 9b86bc0d authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

dry

parent ed39a2b2
No related branches found
No related tags found
No related merge requests found
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def self.models_with_concern(concern)
descendants.select { |model|
model.included_modules.include?(concern)
}
end
def self.model_names_with_concern(concern)
models_with_concern(concern).map(&:name)
end
end
......@@ -103,7 +103,7 @@ class Communication::Block < ApplicationRecord
before_validation :set_university_and_website_from_about, on: :create
def self.permitted_about_types
ApplicationRecord.descendants.select { |model| model.included_modules.include?(WithBlocks) }.map(&:name)
ApplicationRecord.model_names_with_concern(WithBlocks)
end
# When we set data from json, we pass it to the template.
......
......@@ -52,7 +52,7 @@ class Communication::Block::Heading < ApplicationRecord
before_validation :compute_level
def self.permitted_about_types
ApplicationRecord.descendants.select { |model| model.included_modules.include?(WithBlocks) }.map(&:name)
ApplicationRecord.model_names_with_concern(WithBlocks)
end
def references
......
......@@ -105,7 +105,7 @@ class Communication::Website::Permalink < ApplicationRecord
end
def self.permitted_about_types
ApplicationRecord.descendants.select { |model| model.included_modules.include?(WithPermalink) }.map(&:name)
ApplicationRecord.model_names_with_concern(WithPermalink)
end
def pattern
......
......@@ -23,6 +23,6 @@ class User::Favorite < ApplicationRecord
belongs_to :about, polymorphic: true
def self.permitted_about_types
ApplicationRecord.descendants.select { |model| model.included_modules.include?(Favoritable) }.map(&:name)
ApplicationRecord.model_names_with_concern(Favoritable)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment