Sha256: 43fa0e82c0d6b556d84f2bd148905932cc93554e4c3496e07c69c297672779e4

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 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
            lambda { |obj, env| obj }
          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.6.1 lib/grape/formatter/base.rb