Class: Assets::Responder

Inherits:
Object
  • Object
show all
Includes:
AbstractType
Defined in:
lib/assets/responder.rb

Overview

Abstract base class for asset responders

Direct Known Subclasses

New, NotModified

Defined Under Namespace

Classes: New, NotModified

Constant Summary collapse

HEADERS =
IceNine.deep_freeze('Cache-Control' => 'max-age=120, must-revalidate')
NOT_FOUND =
Response.build(
  Response::Status::NOT_FOUND,
  HEADERS.merge('Content-Type' => Assets::Mime::TXT.content_type),
  'Not Found'
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(asset) ⇒ Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call responder

Parameters:

  • asset (Object)

Returns:

  • (Response)


21
22
23
# File 'lib/assets/responder.rb', line 21

def self.call(asset)
  new(asset).response
end

.run(request, asset) ⇒ Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run responder

Parameters:

  • request (Request)
  • asset (Asset)

Returns:

  • (Response)

    response



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/assets/responder.rb', line 34

def self.run(request, asset)
  timestamp = request.if_modified_since

  responder =
    if timestamp && asset.fresh_at?(timestamp)
      NotModified
    else
      New
    end

  responder.call(asset)
end

Instance Method Details

#responseResponse

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return response

Returns:

  • (Response)


53
54
55
# File 'lib/assets/responder.rb', line 53

def response
  Response.new(status, headers, body)
end