Sha256: dceb869a2b3305b30e0d163be4db83e53c2df79adbd0a44859a22612aba75051

Contents?: true

Size: 1.06 KB

Versions: 23

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Praxis
  class ResponseTemplate
    attr_reader :name, :block

    def initialize(response_name, &block)
      @name = response_name
      @block = block
    end

    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

    def describe
      puts 'TODO!!!!!!'
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 lib/praxis/response_template.rb
praxis-2.0.pre.40 lib/praxis/response_template.rb
praxis-2.0.pre.39 lib/praxis/response_template.rb
praxis-2.0.pre.38 lib/praxis/response_template.rb
praxis-2.0.pre.37 lib/praxis/response_template.rb
praxis-2.0.pre.36 lib/praxis/response_template.rb
praxis-2.0.pre.35 lib/praxis/response_template.rb
praxis-2.0.pre.34 lib/praxis/response_template.rb
praxis-2.0.pre.33 lib/praxis/response_template.rb
praxis-2.0.pre.32 lib/praxis/response_template.rb
praxis-2.0.pre.31 lib/praxis/response_template.rb
praxis-2.0.pre.30 lib/praxis/response_template.rb
praxis-2.0.pre.29 lib/praxis/response_template.rb
praxis-2.0.pre.28 lib/praxis/response_template.rb
praxis-2.0.pre.27 lib/praxis/response_template.rb
praxis-2.0.pre.26 lib/praxis/response_template.rb
praxis-2.0.pre.25 lib/praxis/response_template.rb
praxis-2.0.pre.24 lib/praxis/response_template.rb
praxis-2.0.pre.23 lib/praxis/response_template.rb
praxis-2.0.pre.22 lib/praxis/response_template.rb