Sha256: 996dad18fd70ac62e75fe0f2d67e8a00eafee9a6fb40b89a7609e85b9bbf3880

Contents?: true

Size: 1.97 KB

Versions: 12

Compression:

Stored size: 1.97 KB

Contents

require "panda_pal/engine"
require 'panda_pal/plugins'
require 'panda_pal/helpers'

module PandaPal
  class LtiNavigationInUse < StandardError;end
  class NotMounted < StandardError;end

  @@lti_navigation = {}
  @@lti_options = {}
  @@lti_properties = {}
  @@lti_environments = {}
  @@lti_custom_params = {}
  @@lti_private_key = nil

  def self.lti_options= lti_options
    @@lti_options = lti_options
  end

  def self.lti_options
    @@lti_options.deep_dup
  end

  def self.lti_properties= lti_properties
    @@lti_properties = lti_properties
  end

  def self.lti_properties
    @@lti_properties.deep_dup
  end

  def self.lti_environments=(lti_environments)
    @@lti_environments = lti_environments
  end

  def self.lti_environments
    @@lti_environments.deep_dup
  end

  def self.lti_custom_params=(custom_params)
    @@lti_custom_params = custom_params
  end

  def self.lti_custom_params
    @@lti_custom_params.deep_dup
  end

  def self.stage_navigation(navigation, options)
    @@lti_navigation[navigation] ||= {}
    @@lti_navigation[navigation].merge!(options)
  end

  def self.lti_paths
    @@lti_navigation.deep_dup
  end

  def self.lti_private_key
    key = @@lti_private_key.presence
    key ||= ENV['LTI_PRIVATE_KEY'].presence
    key ||= File.read(File.join( File.dirname(__FILE__), "../config/dev_lti_key.key")) if Rails.env.development?
    return nil unless key.present?

    key = OpenSSL::PKey::RSA.new(key) if key.is_a?(String)
    key
  end

  def self.lti_private_key=(v)
    @@lti_private_key = k
  end

  private

  def self.validate_pandapal_config!
    errors = []
    validate_lti_navigation(errors)
    if errors.present?
      lines = errors.map { |e| " - #{e}" }
      raise "PandaPal was not configured correctly:\n#{lines.join("\n")}"
    end
  end

  def self.validate_lti_navigation(errors = [])
    @@lti_navigation.each do |k, v|
      errors << "lti navigation '#{k}' does not have a Route!" unless (LaunchUrlHelpers.launch_url(k) rescue nil)
    end
    errors
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
panda_pal-5.3.6.beta2 lib/panda_pal.rb
panda_pal-5.3.6.beta1 lib/panda_pal.rb
panda_pal-5.3.5 lib/panda_pal.rb
panda_pal-5.3.4 lib/panda_pal.rb
panda_pal-5.3.2 lib/panda_pal.rb
panda_pal-5.3.0 lib/panda_pal.rb
panda_pal-5.2.5 lib/panda_pal.rb
panda_pal-5.2.4 lib/panda_pal.rb
panda_pal-5.2.3 lib/panda_pal.rb
panda_pal-5.2.2 lib/panda_pal.rb
panda_pal-5.2.1 lib/panda_pal.rb
panda_pal-5.2.0 lib/panda_pal.rb