Class: Scorpion::Dependency::CapturedDependency

Inherits:
Scorpion::Dependency show all
Extended by:
Forwardable
Defined in:
lib/scorpion/dependency/captured_dependency.rb

Attributes collapse

Attributes inherited from Scorpion::Dependency

#contract

Instance Method Summary collapse

Methods inherited from Scorpion::Dependency

#==, define, #hash, #inspect, #satisfies?

Constructor Details

#initialize(specific_dependency) ⇒ CapturedDependency

Returns a new instance of CapturedDependency.



28
29
30
# File 'lib/scorpion/dependency/captured_dependency.rb', line 28

def initialize( specific_dependency )
  @specific_dependency = specific_dependency
end

Instance Attribute Details

#instanceObject

Returns the instance that was captured.

Returns:

  • (Object)

    the instance that was captured.



14
15
16
# File 'lib/scorpion/dependency/captured_dependency.rb', line 14

def instance
  @instance
end

#specific_dependency=(value) ⇒ Scorpion::Dependency

Returns the actual dependency to hunt. Used to fetch the single #instance.

Returns:



19
20
21
# File 'lib/scorpion/dependency/captured_dependency.rb', line 19

def specific_dependency
  @specific_dependency
end

Instance Method Details

#fetch(hunt) ⇒ Object



33
34
35
# File 'lib/scorpion/dependency/captured_dependency.rb', line 33

def fetch( hunt )
  @instance ||= specific_dependency.fetch( hunt ) # rubocop:disable Naming/MemoizedInstanceVariableName
end

#releaseObject



38
39
40
# File 'lib/scorpion/dependency/captured_dependency.rb', line 38

def release
  @instance = nil
end

#replicateObject



43
44
45
# File 'lib/scorpion/dependency/captured_dependency.rb', line 43

def replicate
  dup.tap(&:release)
end