Class: Rack::Relations::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/relations/middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, safelist_domains: []) ⇒ Middleware

Returns a new instance of Middleware.



6
7
8
9
# File 'lib/rack/relations/middleware.rb', line 6

def initialize(app, safelist_domains: [])
  @app = app
  @processor = Rack::Relations::Processor.new(safelist_domains: safelist_domains)
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



4
5
6
# File 'lib/rack/relations/middleware.rb', line 4

def app
  @app
end

#processorObject

Returns the value of attribute processor.



4
5
6
# File 'lib/rack/relations/middleware.rb', line 4

def processor
  @processor
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/rack/relations/middleware.rb', line 11

def call(env)
  status, headers, response = @app.call(env)

  response = @processor.perform(response) if headers["Content-Type"].to_s.include?("text/html")

  [status, headers, response]
end