ruby-grape/grape-entity

View on GitHub
lib/grape_entity/exposure/block_exposure.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

module Grape
  class Entity
    module Exposure
      class BlockExposure < Base
        attr_reader :block

        def value(entity, options)
          entity.exec_with_object(options, &@block)
        end

        def dup
          super(&@block)
        end

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

        def valid?(_entity)
          true
        end

        def setup(&block)
          @block = block
        end
      end
    end
  end
end