Module: Strelka::HTTPResponse::Presenters

Defined in:
lib/strelka/httpresponse/presenters.rb

Overview

Hypermedia presentation logic for Strelka HTTP responses

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#presenterObject

The presenter to use when negotiating the response



25
26
27
# File 'lib/strelka/httpresponse/presenters.rb', line 25

def presenter
  @presenter
end

Instance Method Details

#[]Object

Added so we can pass the response object to the presenters as the ‘env`.



29
30
31
# File 'lib/strelka/httpresponse/presenters.rb', line 29

def []( * ) # :nodoc:
  return nil
end

#initializeObject

Initialize some instance variables when a new response is created.



13
14
15
16
# File 'lib/strelka/httpresponse/presenters.rb', line 13

def initialize( * )
  @presenter = nil
  super
end

#present(entity, **options) ⇒ Object

Set the entity that should be rendered to form the response body.



35
36
37
38
39
40
41
42
# File 'lib/strelka/httpresponse/presenters.rb', line 35

def present( entity, **options )
  Yaks::Format.all.each do |format|
    self.for( format.media_type ) do
      opts = options.merge( format: format.format_name, env: self )
      self.presenter.call( entity, opts )
    end
  end
end