class Praxis::ResponseTemplate

Attributes

block[R]
name[R]

Public Class Methods

new(response_name, &block) click to toggle source
# File lib/praxis/response_template.rb, line 7
def initialize(response_name, &block)
  @name = response_name
  @block = block
end

Public Instance Methods

compile(action = nil, **args) click to toggle source
# File lib/praxis/response_template.rb, line 12
def compile(action = nil, **args)
  # Default media_type to the endpoint_definition one, if the block has it in
  # its required args but no value is passed (funky, but can help in the common case)
  if block.parameters.any? { |(type, name)| name == :media_type && type == :keyreq } && action && !(args.key? :media_type)
    media_type = action.endpoint_definition.media_type
    unless media_type
      raise Exceptions::InvalidConfiguration, "Could not default :media_type argument for response template #{@name}." \
                                              " Endpoint #{action.endpoint_definition} does not have an associated mediatype and none was passed"
    end
    args[:media_type] = media_type
  end
  Praxis::ResponseDefinition.new(name, **args, &block)
end
describe() click to toggle source
# File lib/praxis/response_template.rb, line 26
def describe
  puts 'TODO!!!!!!'
end