Sha256: afff808f9732791d6a8263195b6af22b88f568ad0b8342aca8149284e9346d98

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

module Praxis

  class ResponseTemplate
    attr_reader :name, :block, :application

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

    def compile(action=nil, **args)
      # Default media_type to the resource_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
        unless args.has_key? :media_type
          media_type = action.resource_definition.media_type
          unless media_type
            raise Exceptions::InvalidConfiguration.new(
              "Could not default :media_type argument for response template #{@name}." +
               " Resource #{action.resource_definition} does not have an associated mediatype and none was passed"
            )
          end
          args[:media_type] = media_type
        end
      end
      Praxis::ResponseDefinition.new(name, application, **args, &block)   
    end

    def describe
      puts "TODO!!!!!!"
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
praxis-0.22.pre.2 lib/praxis/response_template.rb
praxis-0.22.pre.1 lib/praxis/response_template.rb