Sha256: f55657b3cb73e9fb1959d5113989817974b736a4773017a7c798e629806d8ef4

Contents?: true

Size: 787 Bytes

Versions: 14

Compression:

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

14 entries across 14 versions & 1 rubygems

Version Path
grape-1.2.4 lib/grape/formatter.rb
grape-1.2.3 lib/grape/formatter.rb
grape-1.2.2 lib/grape/formatter.rb
grape-1.2.1 lib/grape/formatter.rb
grape-1.2.0 lib/grape/formatter.rb
grape-1.1.0 lib/grape/formatter.rb
grape-1.0.3 lib/grape/formatter.rb
grape-1.0.2 lib/grape/formatter.rb
grape-1.0.1 lib/grape/formatter.rb
grape-1.0.0 lib/grape/formatter.rb
grape-0.19.2 lib/grape/formatter.rb
grape-0.19.1 lib/grape/formatter.rb
grape-0.19.0 lib/grape/formatter.rb
grape-0.18.0 lib/grape/formatter.rb