File: block_exposure.rb

package info (click to toggle)
ruby-grape-entity 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 456 kB
  • sloc: ruby: 3,335; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 517 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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