Class: DynamicImage::Picture::FormatPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_image/picture/format_policy.rb

Overview

DynamicImage Picture Format Policy

Decides what a responsive image is rendered in. The source gets the best format available for output, transcoded unconditionally. The img gets one of COMPATIBLE_FORMATS.

See Also:

Constant Summary collapse

DEFAULT_SOURCE_FORMAT =

The format the candidates are rendered in when the view doesn't ask for one.

:webp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, requested = nil) ⇒ FormatPolicy

Returns a new instance of FormatPolicy.

Parameters:

  • record (DynamicImage::Model)

    the image

  • requested (Symbol, Array<Symbol>, nil) (defaults to: nil)

    the format the candidates are rendered in. A symbol forces that format, an array is negotiated, nil takes the default.



24
25
26
27
# File 'lib/dynamic_image/picture/format_policy.rb', line 24

def initialize(record, requested = nil)
  @record = record
  @requested = requested
end

Instance Attribute Details

#recordDynamicImage::Model (readonly)

Returns:



19
20
21
# File 'lib/dynamic_image/picture/format_policy.rb', line 19

def record
  @record
end

#requestedObject (readonly)

Returns the value of attribute requested.



19
# File 'lib/dynamic_image/picture/format_policy.rb', line 19

attr_reader :record, :requested

Instance Method Details

#fallbackDynamicImage::Format

The format the fallback image is rendered in.



39
40
41
# File 'lib/dynamic_image/picture/format_policy.rb', line 39

def fallback
  @fallback ||= resolve(fallback_formats)
end

#sourceDynamicImage::Format

The format the candidates are rendered in.



32
33
34
# File 'lib/dynamic_image/picture/format_policy.rb', line 32

def source
  @source ||= resolve(requested || default_source)
end