File: lazy_block.rb

package info (click to toggle)
ruby-grape 1.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,156 kB
  • sloc: ruby: 25,265; makefile: 7
file content (27 lines) | stat: -rw-r--r-- 393 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

module Grape
  module Util
    class LazyBlock
      def initialize(&new_block)
        @block = new_block
      end

      def evaluate_from(configuration)
        @block.call(configuration)
      end

      def evaluate
        @block.call({})
      end

      def lazy?
        true
      end

      def to_s
        evaluate.to_s
      end
    end
  end
end