Sha256: 034b748b9477225774462fb3fbe5b3309fbe4cb682ff1c6e1891459e0bcc5268

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

require "scorpion/dependency"

module Scorpion
  class Dependency
    class CapturedDependency < Scorpion::Dependency
      extend Forwardable

      # ============================================================================
      # @!group Attributes
      #

      # @!attribute
      # @return [Object] the instance that was captured.
        attr_reader :instance

      # @!attribute
      # @return [Scorpion::Dependency] the actual dependency to hunt. Used to fetch the
      #   single {#instance}.
        attr_reader :specific_dependency
        private :specific_dependency


      delegate [ :contract, :satisfies? ] => :specific_dependency

      #
      # @!endgroup Attributes

      def initialize( specific_dependency )
        @specific_dependency = specific_dependency
      end

      # @see Dependency#fetch
      def fetch( hunt )
        @instance ||= specific_dependency.fetch( hunt )
      end

      # @see Dependency#release
      def release
        @instance = nil
      end

      # @see Dependency#replicate
      def replicate
        dup.tap(&:release)
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scorpion-ioc-1.0.4 lib/scorpion/dependency/captured_dependency.rb
scorpion-ioc-1.0.3 lib/scorpion/dependency/captured_dependency.rb
scorpion-ioc-1.0.2 lib/scorpion/dependency/captured_dependency.rb
scorpion-ioc-1.0.1 lib/scorpion/dependency/captured_dependency.rb
scorpion-ioc-1.0.0 lib/scorpion/dependency/captured_dependency.rb