Sha256: 6399666be01d5dce97e7d9b400515dd34300675b5550215c8b9583c3a8d80c13

Contents?: true

Size: 979 Bytes

Versions: 4

Compression:

Stored size: 979 Bytes

Contents

require 'scorpion/prey'

module Scorpion
  class Prey
    class CapturedPrey < Scorpion::Prey
      extend Forwardable

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

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

      # @!attribute
      # @return [Scorpion::Prey] the actual prey to hunt. Used to fetch the
      #   single {#instance}.
        attr_reader :specific_prey
        private :specific_prey


      delegate [:contract,:traits,:satisfies?] => :specific_prey

      #
      # @!endgroup Attributes

      def initialize( specific_prey )
        @specific_prey = specific_prey
      end

      # @see Prey#fetch
      def fetch( scorpion, *args, &block )
        @instance ||= specific_prey.fetch( scorpion, *args, &block )
      end

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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
scorpion-ioc-0.3.1 lib/scorpion/prey/captured_prey.rb
scorpion-ioc-0.3.0 lib/scorpion/prey/captured_prey.rb
scorpion-ioc-0.2.0 lib/scorpion/prey/captured_prey.rb
scorpion-ioc-0.1.0 lib/scorpion/prey/captured_prey.rb