Sha256: 11154258c30b49bd1b00e9087734f4390242b221e700dd277cc18fcf76a86504

Contents?: true

Size: 728 Bytes

Versions: 11

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true

module Grape
  class Entity
    module Exposure
      class FormatterExposure < Base
        attr_reader :format_with

        def setup(format_with)
          @format_with = format_with
        end

        def dup_args
          [*super, format_with]
        end

        def ==(other)
          super && @format_with == other.format_with
        end

        def value(entity, _options)
          formatters = entity.class.formatters
          if formatters[@format_with]
            entity.exec_with_attribute(attribute, &formatters[@format_with])
          else
            entity.send(@format_with, entity.delegate_attribute(attribute))
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
grape-entity-1.0.1 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-1.0.0 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.10.2 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.10.1 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.10.0 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.9.0 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.8.2 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.8.1 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.8.0 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.7.1 lib/grape_entity/exposure/formatter_exposure.rb
grape-entity-0.7.0 lib/grape_entity/exposure/formatter_exposure.rb