Class: Trinity::Handler::Initializer

Inherits:
Trinity::Handler show all
Defined in:
lib/trinity/handler/initializer.rb

Overview

Initialize the appropriate environment variables with a valid resource URI which will be used as the subject of the current request

Instance Attribute Summary

Instance Method Summary

Methods inherited from Trinity::Handler

#not_found, #query, #redirect

Constructor Details

- (Initializer) initialize(application, repository = nil, options = {})

A new instance of Initializer



9
10
11
12
# File 'lib/trinity/handler/initializer.rb', line 9

def initialize(application, repository = nil, options = {})
  @options = options
  super(application, repository)
end

Instance Attribute Details

- (Object) options (readonly)

Returns the value of attribute options



7
8
9
# File 'lib/trinity/handler/initializer.rb', line 7

def options
  @options
end

Instance Method Details

- (Object) call(env)



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/trinity/handler/initializer.rb', line 14

def call(env)
  env['trinity.resource'] = RDF::URI.new(Addressable::URI.new({
    :scheme => env['rack.url_scheme'],
    :host   => options[:host] || env['SERVER_NAME'],
    :port   => options[:port] || env['SERVER_PORT'],
    :path   => env['REQUEST_URI'],
    :query  => env['QUERY_STRING'].to_s.size > 0 ? env['QUERY_STRING'] : nil,
  }))
  env['trinity.subject'] = env['trinity.resource']
  super
end