Class: Rack::LTI::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/rack/lti/config.rb

Constant Summary collapse

DEFAULT =
{
  app_path:        '/',
  config_path:     '/lti/config.xml',
  description:     'An LTI Application.',
  launch_path:     '/lti/launch',
  nonce_validator: true,
  redirect:        true,
  success:         ->(lti, req, res) {
    req.session['launch_params'] = lti if req.env['rack.session']
  },
  time_limit:      60*60,
  title:           'LTI App'
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



19
20
21
22
# File 'lib/rack/lti/config.rb', line 19

def initialize(options = {})
  DEFAULT.merge(options).each { |k, v| self[k] = v }
  instance_eval { yield(self) } if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/rack/lti/config.rb', line 50

def method_missing(method, *args, &block)
  if method.match(/=$/)
    self[method.to_s[0..-2].to_sym] = args.first
  elsif self.has_key?(method)
    self[method]
  else
    super
  end
end

Instance Method Details

#public?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rack/lti/config.rb', line 34

def public?
  self[:consumer_key].nil? && self[:consumer_secret].nil?
end

#to_xml(request, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rack/lti/config.rb', line 38

def to_xml(request, options = {})
  options = options.merge(get_extensions(request))

  # Stringify keys for IMS::LTI
  config = self.merge(options).inject({}) do |h, v|
    h[v[0].to_s] = v[1]
    h
  end

  IMS::LTI::ToolConfig.new(config).to_xml(indent: 2)
end