Sha256: c1fa61020a95d2645fd824f60843d8ee086077e8da7cdcd5d80bd4fbac8c6fc9

Contents?: true

Size: 896 Bytes

Versions: 16

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

# Based on https://github.com/HornsAndHooves/lazy_object

module Grape
  module Util
    class LazyObject < BasicObject
      attr_reader :callable

      def initialize(&callable)
        @callable = callable
      end

      def __target_object__
        @__target_object__ ||= callable.call
      end

      def ==(other)
        __target_object__ == other
      end

      def !=(other)
        __target_object__ != other
      end

      def !
        !__target_object__
      end

      def method_missing(method_name, *args, &block)
        if __target_object__.respond_to?(method_name)
          __target_object__.send(method_name, *args, &block)
        else
          super
        end
      end

      def respond_to_missing?(method_name, include_priv = false)
        __target_object__.respond_to?(method_name, include_priv)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
grape-2.0.0 lib/grape/util/lazy_object.rb
grape-1.8.0 lib/grape/util/lazy_object.rb
grape-1.7.1 lib/grape/util/lazy_object.rb
grape-1.7.0 lib/grape/util/lazy_object.rb
grape-1.6.2 lib/grape/util/lazy_object.rb
grape-1.6.1 lib/grape/util/lazy_object.rb
grape-1.6.0 lib/grape/util/lazy_object.rb
grape-1.5.3 lib/grape/util/lazy_object.rb
grape-1.5.2 lib/grape/util/lazy_object.rb
grape-1.5.1 lib/grape/util/lazy_object.rb
grape-1.5.0 lib/grape/util/lazy_object.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/lib/grape/util/lazy_object.rb
grape-1.4.0 lib/grape/util/lazy_object.rb
grape-1.3.3 lib/grape/util/lazy_object.rb
grape-1.3.2 lib/grape/util/lazy_object.rb
grape-1.3.1 lib/grape/util/lazy_object.rb