Module: Scorpion
- Included in:
- ChainHunter, Hunter
- Defined in:
- lib/scorpion.rb,
lib/scorpion/hunt.rb,
lib/scorpion/nest.rb,
lib/scorpion/error.rb,
lib/scorpion/rails.rb,
lib/scorpion/rspec.rb,
lib/scorpion/hunter.rb,
lib/scorpion/method.rb,
lib/scorpion/object.rb,
lib/scorpion/stinger.rb,
lib/scorpion/version.rb,
lib/scorpion/attribute.rb,
lib/scorpion/rails/job.rb,
lib/scorpion/dependency.rb,
lib/scorpion/rails/nest.rb,
lib/scorpion/chain_hunter.rb,
lib/scorpion/rails/mailer.rb,
lib/scorpion/rspec/helper.rb,
lib/scorpion/attribute_set.rb,
lib/scorpion/rails/railtie.rb,
lib/scorpion/dependency_map.rb,
lib/scorpion/rails/controller.rb,
lib/scorpion/object_constructor.rb,
lib/scorpion/rails/active_record.rb,
lib/scorpion/rails/active_record/model.rb,
lib/scorpion/dependency/class_dependency.rb,
lib/scorpion/dependency/module_dependency.rb,
lib/scorpion/rails/active_record/relation.rb,
lib/scorpion/dependency/builder_dependency.rb,
lib/scorpion/dependency/argument_dependency.rb,
lib/scorpion/dependency/captured_dependency.rb,
lib/scorpion/rails/active_record/association.rb
Defined Under Namespace
Modules: Method, Object, Rails, Rspec, Stinger Classes: ArityMismatch, Attribute, AttributeSet, BuilderRequiredError, ChainHunter, Dependency, DependencyMap, Error, Hunt, Hunter, Nest, ObjectConstructor, UnsuccessfulHunt
Constant Summary collapse
- VERSION_NUMBER =
"0.5.9"
- VERSION_SUFFIX =
""
- VERSION =
"#{VERSION_NUMBER}#{VERSION_SUFFIX}"
Convenience Methods collapse
-
#logger ⇒ Logger
Logger for the Scorpion framework to use.
Convenience Methods collapse
-
.fetch(dependencies, &block) ⇒ Object
Hunt for dependency from the primary Scorpion #instance.
-
.fetch_by_traits(dependencies, &block) ⇒ Object
Hunt for dependency from the primary Scorpion #instance.
-
.instance ⇒ Scorpion
Main scorpion for the app.
-
.logger ⇒ Logger
Logger for the Scorpion framework to use.
- .logger=(value) ⇒ Object
-
.prepare(reset = false, &block) ⇒ Object
Prepare the #instance for hunting.
Instance Method Summary collapse
-
#build_nest ⇒ Scorpion::Nest
A nest that uses this scorpion as the mother.
-
#destroy ⇒ Object
Free up any captured dependency and release any long-held resources.
-
#execute(hunt) ⇒ Object
Execute the
hunt
returning the desired dependency. -
#fetch(contract, *arguments, **dependencies, &block) ⇒ Object
Hunts for an object that satisfies the requested
contract
regardless of traits. -
#fetch_by_traits(contract, traits, *arguments, **dependencies, &block) ⇒ Object
Hunts for an object that satisfies the requested
contract
andtraits
. -
#inject(target) ⇒ target
Inject the #target with all non-lazy dependencies.
-
#new(object_class, *arguments, **dependencies, &block) ⇒ Scorpion::Object
Explicitly spawn an instance of #object_class and inject it's dependencies.
-
#replicate(&block) ⇒ Scorpion
Creates a new Scorpion copying the current configuration any any currently captured dependency.
-
#reset ⇒ Object
Reset the hunting map and clear all dependencies.
-
#spawn(hunt, object_class, *arguments, **dependencies, &block) ⇒ Scorpion::Object
Creates a new object and feeds it it's dependencies.
Instance Attribute Details
Class Method Details
.fetch(dependencies, &block) ⇒ Object
Hunt for dependency from the primary Scorpion #instance.
133 134 135 |
# File 'lib/scorpion.rb', line 133 def self.fetch( dependencies, &block ) instance.fetch dependencies, &block end |
.fetch_by_traits(dependencies, &block) ⇒ Object
Hunt for dependency from the primary Scorpion #instance.
139 140 141 |
# File 'lib/scorpion.rb', line 139 def self.fetch_by_traits( dependencies, &block ) instance.fetch_by_traits dependencies, &block end |
.instance ⇒ Scorpion
Returns main scorpion for the app.
118 119 120 |
# File 'lib/scorpion.rb', line 118 def self.instance @instance end |
.logger ⇒ Logger
Returns logger for the Scorpion framework to use.
145 146 147 |
# File 'lib/scorpion.rb', line 145 def self.logger @logger ||= defined?( ::Rails ) ? ::Rails.logger : Logger.new( STDOUT ) end |
.logger=(value) ⇒ Object
148 149 150 |
# File 'lib/scorpion.rb', line 148 def self.logger=( value ) @logger = value end |
.prepare(reset = false, &block) ⇒ Object
Prepare the #instance for hunting.
126 127 128 129 |
# File 'lib/scorpion.rb', line 126 def self.prepare( reset = false, &block ) @instance.reset if reset instance.prepare &block end |
Instance Method Details
#build_nest ⇒ Scorpion::Nest
Returns a nest that uses this scorpion as the mother.
96 97 98 |
# File 'lib/scorpion.rb', line 96 def build_nest Scorpion::Nest.new( self ) end |
#destroy ⇒ Object
Free up any captured dependency and release any long-held resources.
87 88 89 |
# File 'lib/scorpion.rb', line 87 def destroy reset end |
#execute(hunt) ⇒ Object
Execute the hunt
returning the desired dependency.
75 76 77 |
# File 'lib/scorpion.rb', line 75 def execute( hunt ) fail "Not implemented" end |
#fetch(contract, *arguments, **dependencies, &block) ⇒ Object
Hunts for an object that satisfies the requested contract
regardless of
traits.
36 37 38 |
# File 'lib/scorpion.rb', line 36 def fetch( contract, *arguments, **dependencies, &block ) fetch_by_traits( contract, nil, *arguments, **dependencies, &block ) end |
#fetch_by_traits(contract, traits, *arguments, **dependencies, &block) ⇒ Object
Hunts for an object that satisfies the requested contract
and traits
.
28 29 30 31 |
# File 'lib/scorpion.rb', line 28 def fetch_by_traits( contract, traits, *arguments, **dependencies, &block ) hunt = Hunt.new( self, contract, traits, *arguments, **dependencies, &block ) execute hunt end |
#inject(target) ⇒ target
Inject the #target with all non-lazy dependencies.
56 57 58 59 60 61 |
# File 'lib/scorpion.rb', line 56 def inject( target ) hunt = Scorpion::Hunt.new self, nil, nil hunt.inject target target end |
#new(object_class, *arguments, **dependencies, &block) ⇒ Scorpion::Object
Explicitly spawn an instance of #object_class and inject it's dependencies.
67 68 69 70 |
# File 'lib/scorpion.rb', line 67 def new( object_class, *arguments, **dependencies, &block ) hunt = Hunt.new( self, object_class, nil, *arguments, **dependencies, &block ) Scorpion::Dependency::ClassDependency.new( object_class ).fetch( hunt ) end |
#replicate(&block) ⇒ Scorpion
Creates a new Scorpion copying the current configuration any any currently captured dependency.
82 83 84 |
# File 'lib/scorpion.rb', line 82 def replicate( &block ) fail "Not implemented" end |
#reset ⇒ Object
Reset the hunting map and clear all dependencies.
92 93 |
# File 'lib/scorpion.rb', line 92 def reset end |
#spawn(hunt, object_class, *arguments, **dependencies, &block) ⇒ Scorpion::Object
Creates a new object and feeds it it's dependencies.
45 46 47 48 49 50 51 |
# File 'lib/scorpion.rb', line 45 def spawn( hunt, object_class, *arguments, **dependencies, &block ) if object_class < Scorpion::Object object_class.spawn hunt, *arguments, **dependencies, &block else object_class.new *arguments, &block end end |