lib/panda_pal.rb in panda_pal-5.4.0.beta7 vs lib/panda_pal.rb in panda_pal-5.4.0.beta8

- old
+ new

@@ -11,10 +11,11 @@ @@lti_navigation = {} @@lti_options = {} @@lti_properties = {} @@lti_environments = {} @@lti_custom_params = {} + @@extensions = {} @@lti_private_key = nil def self.lti_options= lti_options @@lti_options = lti_options end @@ -68,12 +69,34 @@ def self.lti_private_key=(v) @@lti_private_key = k end + def self.register_extension(type, modul) + type = normalize_ext_type(type) + @@extensions[type] ||= [] + @@extensions[type] << modul + end + + def self.extensions_for(type) + (@@extensions[normalize_ext_type(type)] || []).uniq + end + + def self.resolved_extensions_for(type) + extensions_for(type).map do |ext| + ext.to_s.safe_constantize + end.compact + end + private + def self.normalize_ext_type(type) + type = type.to_s + type = "#{self.to_s}::#{type}" unless type.starts_with?('::') || type.starts_with?(self.to_s) + type + end + def self.validate_pandapal_config! errors = [] validate_lti_navigation(errors) if errors.present? lines = errors.map { |e| " - #{e}" } @@ -87,5 +110,7 @@ errors << "lti navigation '#{k}' does not have a Route!" unless (LaunchUrlHelpers.launch_url(k) rescue nil) end errors end end + +PandaPal.register_extension 'Organization', '::OrganizationExtension'