forked from nbgallery/nbgallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextendable_model.rb
executable file
·31 lines (29 loc) · 970 Bytes
/
extendable_model.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Extension support for models
module ExtendableModel
# Load extensions when included by a model
def self.included(klass)
# This array should contain any attributes added to the model
klass.meta_eval do
attr_accessor :extension_attributes
end
klass.class_eval do
self.extension_attributes = []
end
# Return if no extensions defined for this class
key = klass.to_s.to_sym
return if GalleryConfig.dig(:extensions, key).blank?
# Load additional methods from the extensions
GalleryConfig.extensions[key].each do |extension|
Rails.logger.info("Adding #{extension} extension to #{key}")
klass.class_eval do
# Trigger Rails autoload
include extension.constantize
end
if extension.constantize.const_defined?('ClassMethods') # rubocop: disable Style/Next
klass.meta_eval do
prepend "#{extension}::ClassMethods".constantize
end
end
end
end
end