Sha256: 6cea328627de296be2665add0419cd79438889c48951ad56bbc3fa074d5b960f

Contents?: true

Size: 708 Bytes

Versions: 11

Compression:

Stored size: 708 Bytes

Contents

module Grape
  module Formatter
    module Base

      class << self

        FORMATTERS = {
          :json => 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

11 entries across 11 versions & 1 rubygems

Version Path
grape-0.6.0 lib/grape/formatter/base.rb
grape-0.5.0 lib/grape/formatter/base.rb
grape-0.4.1 lib/grape/formatter/base.rb
grape-0.4.0 lib/grape/formatter/base.rb
grape-0.3.2 lib/grape/formatter/base.rb
grape-0.3.1 lib/grape/formatter/base.rb
grape-0.3.0 lib/grape/formatter/base.rb
grape-0.2.6 lib/grape/formatter/base.rb
grape-0.2.5 lib/grape/formatter/base.rb
grape-0.2.4 lib/grape/formatter/base.rb
grape-0.2.3 lib/grape/formatter/base.rb