Sha256: f34db3f00354f22f2f5fd66da387e0446a4401624d45230a0a6f4a55eea054ef

Contents?: true

Size: 788 Bytes

Versions: 3

Compression:

Stored size: 788 Bytes

Contents

module Grape
  module Formatter
    extend Util::Registrable

    class << self
      def builtin_formmaters
        @builtin_formatters ||= {
          json: Grape::Formatter::Json,
          jsonapi: Grape::Formatter::Json,
          serializable_hash: Grape::Formatter::SerializableHash,
          txt: Grape::Formatter::Txt,
          xml: Grape::Formatter::Xml
        }
      end

      def formatters(options)
        builtin_formmaters.merge(default_elements).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

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/formatter.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/formatter.rb
grape-1.2.5 lib/grape/formatter.rb