Sha256: 98d1504d1545e937a0a28744b7960b6d59d598c33d5eee52036d1693d8a43b6e

Contents?: true

Size: 679 Bytes

Versions: 9

Compression:

Stored size: 679 Bytes

Contents

# frozen_string_literal: true

module Bolt
  module Util
    class OnAccess
      def initialize(&block)
        @constructor = block
        @obj = nil
      end

      # If a method is called and we haven't constructed the object,
      # construct it. Then pass the call to the object.
      # rubocop:disable Style/MethodMissingSuper
      # rubocop:disable Style/MissingRespondToMissing
      def method_missing(method, *args, &block)
        if @obj.nil?
          @obj = @constructor.call
        end

        @obj.send(method, *args, &block)
      end
      # rubocop:enable Style/MethodMissingSuper
      # rubocop:enable Style/MissingRespondToMissing
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bolt-0.21.3 lib/bolt/util/on_access.rb
bolt-0.21.2 lib/bolt/util/on_access.rb
bolt-0.21.1 lib/bolt/util/on_access.rb
bolt-0.21.0 lib/bolt/util/on_access.rb
bolt-0.20.7 lib/bolt/util/on_access.rb
bolt-0.20.6 lib/bolt/util/on_access.rb
bolt-0.20.5 lib/bolt/util/on_access.rb
bolt-0.20.3 lib/bolt/util/on_access.rb
bolt-0.20.2 lib/bolt/util/on_access.rb