Class: Scorpion::Dependency
- Inherits:
-
Object
- Object
- Scorpion::Dependency
- Defined in:
- lib/scorpion/dependency.rb,
lib/scorpion/dependency/class_dependency.rb,
lib/scorpion/dependency/module_dependency.rb,
lib/scorpion/dependency/builder_dependency.rb,
lib/scorpion/dependency/argument_dependency.rb,
lib/scorpion/dependency/captured_dependency.rb
Overview
Direct Known Subclasses
ArgumentDependency, BuilderDependency, CapturedDependency, ClassDependency, ModuleDependency
Defined Under Namespace
Classes: ArgumentDependency, BuilderDependency, CapturedDependency, ClassDependency, ModuleDependency
Attributes collapse
-
#contract ⇒ Class, ...
Contract describing the desired behavior of the dependency.
Class Method Summary collapse
-
.define(contract, options = {}, &builder) ⇒ Dependency
Define dependency based on the desired contract.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#fetch(hunt) ⇒ Object
Fetch an instance of the dependency.
- #hash ⇒ Object
-
#initialize(contract) ⇒ Dependency
constructor
A new instance of Dependency.
- #inspect ⇒ Object
-
#release ⇒ Object
Release the dependency, freeing up any long held resources.
-
#replicate ⇒ Dependency
Replicate the Dependency.
-
#satisfies?(contract) ⇒ Boolean
If the dependency satisfies the required contract.
Constructor Details
#initialize(contract) ⇒ Dependency
Returns a new instance of Dependency.
22 23 24 |
# File 'lib/scorpion/dependency.rb', line 22 def initialize( contract ) @contract = contract end |
Instance Attribute Details
#contract ⇒ Class, ...
Returns contract describing the desired behavior of the dependency.
17 18 19 |
# File 'lib/scorpion/dependency.rb', line 17 def contract @contract end |
Class Method Details
.define(contract, options = {}, &builder) ⇒ Dependency
Define dependency based on the desired contract.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/scorpion/dependency.rb', line 79 def define( contract, = {}, &builder ) if .key?( :return ) Scorpion::Dependency::BuilderDependency.new( contract ) do [:return] end elsif with = [ :with ] Scorpion::Dependency::BuilderDependency.new( contract, with ) elsif block_given? Scorpion::Dependency::BuilderDependency.new( contract, builder ) # Allow a Class/Module to define a #create method that will resolve # and return an instance of itself. Do not automatically inherit the # #create method so only consider it if the owner of the method is the # contract itself. elsif contract.respond_to?( :create ) && contract.singleton_methods( false ).include?( :create ) Scorpion::Dependency::BuilderDependency.new( contract ) do |hunt, *args, &block| contract.create hunt, *args, &block end else dependency_class( contract ).new( contract, &builder ) end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
48 49 50 51 |
# File 'lib/scorpion/dependency.rb', line 48 def ==( other ) return unless other self.class == other.class && contract == other.contract end |
#fetch(hunt) ⇒ Object
Fetch an instance of the dependency.
34 35 36 |
# File 'lib/scorpion/dependency.rb', line 34 def fetch( hunt ) fail "Not Implemented" end |
#hash ⇒ Object
54 55 56 |
# File 'lib/scorpion/dependency.rb', line 54 def hash self.class.hash ^ contract.hash end |
#inspect ⇒ Object
58 59 60 61 62 |
# File 'lib/scorpion/dependency.rb', line 58 def inspect result = "<#{ contract.inspect }" result << ">" result end |
#release ⇒ Object
Release the dependency, freeing up any long held resources.
39 40 |
# File 'lib/scorpion/dependency.rb', line 39 def release end |
#replicate ⇒ Dependency
Replicate the Dependency.
44 45 46 |
# File 'lib/scorpion/dependency.rb', line 44 def replicate dup end |
#satisfies?(contract) ⇒ Boolean
Returns if the dependency satisfies the required contract.
27 28 29 |
# File 'lib/scorpion/dependency.rb', line 27 def satisfies?( contract ) satisfies_contract?( contract ) end |