Sha256: 0c7cb81d577a62b28750bb326b4576a0650feaf3abca6795d81699721b768555

Contents?: true

Size: 634 Bytes

Versions: 4

Compression:

Stored size: 634 Bytes

Contents

module Subtle
  class LazyCover < Cover
    include Subtle::StrictCoverMethods

    def initialize(block_that_creates_the_object)
      @block = block_that_creates_the_object
    end

    alias :the_original_subject_from_the_base_class :the_original_subject
    def the_original_subject
      setup_the_subject
      the_original_subject_from_the_base_class
    end

    private

    alias :old_method_missing :method_missing
    def method_missing(meth, *args, &blk)
      setup_the_subject
      old_method_missing meth, *args, &blk
    end

    def setup_the_subject
      @subject = @block.call if @subject.nil?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
subtle-1.2.0 lib/subtle/lazy_cover.rb
subtle-1.1.1 lib/subtle/lazy_cover.rb
subtle-1.1.0 lib/subtle/lazy_cover.rb
subtle-1.0.0 lib/subtle/lazy_cover.rb