Sha256: 715d3e690f05516f7458c2c2de4060907c2a7cd5cf4f2dd0df6826442d0192f6

Contents?: true

Size: 732 Bytes

Versions: 3

Compression:

Stored size: 732 Bytes

Contents

module Grape
  module Formatter
    module Base
      class << self
        FORMATTERS = {
          json: Grape::Formatter::Json,
          jsonapi: Grape::Formatter::Json,
          serializable_hash: Grape::Formatter::SerializableHash,
          txt: Grape::Formatter::Txt,
          xml: Grape::Formatter::Xml
        }

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

        def formatter_for(api_format, options = {})
          spec = formatters(options)[api_format]
          case spec
          when nil
            ->(obj, _env) { obj }
          when Symbol
            method(spec)
          else
            spec
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-0.14.0 lib/grape/formatter/base.rb
grape-0.13.0 lib/grape/formatter/base.rb
grape-0.12.0 lib/grape/formatter/base.rb