Sha256: fb633114570fcc9eacdcceb5e92e79bac78f322478a2ec799a788706a44a453c

Contents?: true

Size: 736 Bytes

Versions: 7

Compression:

Stored size: 736 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

7 entries across 7 versions & 2 rubygems

Version Path
grape-security-0.8.0 lib/grape/formatter/base.rb
grape-0.11.0 lib/grape/formatter/base.rb
grape-0.10.1 lib/grape/formatter/base.rb
grape-0.10.0 lib/grape/formatter/base.rb
grape-0.9.0 lib/grape/formatter/base.rb
grape-0.8.0 lib/grape/formatter/base.rb
grape-0.7.0 lib/grape/formatter/base.rb