Sha256: 5e47b677ca05697764b8f5ec1412e9d9c485c948994253e9f6117c359548e243

Contents?: true

Size: 689 Bytes

Versions: 1

Compression:

Stored size: 689 Bytes

Contents

module Grape
  module ErrorFormatter
    module Base

      class << self

        FORMATTERS = {
          :json => Grape::ErrorFormatter::Json,
          :txt => Grape::ErrorFormatter::Txt,
          :xml => Grape::ErrorFormatter::Xml
        }

        def formatters(options)
          FORMATTERS.merge(options[:error_formatters] || {})
        end

        def formatter_for(api_format, options = {})
          spec = formatters(options)[api_format]
          case spec
          when nil
            lambda { |message, backtrace, options| message }
          when Symbol
            method(spec)
          else
            spec
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-0.2.3 lib/grape/error_formatter/base.rb