has_backends.rb 485 B

1234567891011121314151617181920
  1. module Mixin
  2. module HasBackends
  3. extend ActiveSupport::Concern
  4. included do
  5. class_attribute :backends do
  6. Set.new
  7. end
  8. self_path = ActiveSupport::Dependencies.search_for_file name.underscore
  9. backends_path = self_path.delete_suffix File.extname(self_path)
  10. Mixin::RequiredSubPaths.eager_load_recursive backends_path
  11. backends = "#{name}::Backend".constantize.descendants
  12. self.backends = Set.new(backends)
  13. end
  14. end
  15. end