Module: Scorpion
- Included in:
- ChainHunter, Hunter
- Defined in:
- lib/scorpion.rb,
lib/scorpion/hunt.rb,
lib/scorpion/nest.rb,
lib/scorpion/rack.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/rack/env.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/rack/middleware.rb,
lib/scorpion/rails/controller.rb,
lib/scorpion/rails/active_record.rb,
lib/scorpion/rails/active_record/model.rb,
lib/scorpion/dependency/class_dependency.rb,
lib/scorpion/rack/missing_scorpion_error.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, Rack, Rails, Rspec, Stinger Classes: ArityMismatch, Attribute, AttributeSet, BuilderRequiredError, ChainHunter, ContractMismatchError, Dependency, DependencyMap, Error, Hunt, Hunter, Nest, UnsuccessfulHunt
Constant Summary collapse
- VERSION_NUMBER =
"1.0.10".freeze
- VERSION_SUFFIX =
"".freeze
- VERSION =
"#{ VERSION_NUMBER }#{ VERSION_SUFFIX }".freeze
Convenience Methods collapse
-
#instance ⇒ Scorpion
Main scorpion for the app.
-
#logger ⇒ Logger
Logger for the Scorpion framework to use.
Convenience Methods collapse
-
.fetch(dependencies, &block) ⇒ Object
Hunt for dependency from the primary Scorpion #instance.
-
.instance ⇒ Scorpion
Main scorpion for the app.
- .instance=(scorpion) ⇒ Object
-
.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, &block) ⇒ Object
Hunts for an object that satisfies the requested ‘contract`.
-
#inject(target) ⇒ target
Inject the #target with all non-lazy dependencies.
-
#new(object_class, *arguments, &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, &block) ⇒ Scorpion::Object
Creates a new object and feeds it it’s dependencies.
Instance Attribute Details
#instance ⇒ Scorpion
Returns main scorpion for the app.
111 112 113 114 |
# File 'lib/scorpion.rb', line 111 def self.instance @instance_referenced = true @instance end |
Class Method Details
.fetch(dependencies, &block) ⇒ Object
Hunt for dependency from the primary Scorpion #instance.
139 140 141 |
# File 'lib/scorpion.rb', line 139 def self.fetch( dependencies, &block ) instance.fetch dependencies, &block end |
.instance ⇒ Scorpion
Returns main scorpion for the app.
111 112 113 114 |
# File 'lib/scorpion.rb', line 111 def self.instance @instance_referenced = true @instance end |
.instance=(scorpion) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/scorpion.rb', line 118 def self.instance=( scorpion ) if @instance_referenced logger.warn "Replacing the global Scorpion.instance will not update any Scorpion::Nest instances created with the original scorpion." if warn_global_replace # rubocop:disable Metrics/LineLength @instance_referenced = false end @instance = scorpion 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
149 150 151 |
# File 'lib/scorpion.rb', line 149 def self.logger=( value ) @logger = value end |
Instance Method Details
#build_nest ⇒ Scorpion::Nest
Returns a nest that uses this scorpion as the mother.
87 88 89 |
# File 'lib/scorpion.rb', line 87 def build_nest Scorpion::Nest.new( self ) end |
#destroy ⇒ Object
Free up any captured dependency and release any long-held resources.
78 79 80 |
# File 'lib/scorpion.rb', line 78 def destroy reset end |
#execute(hunt) ⇒ Object
Execute the ‘hunt` returning the desired dependency.
66 67 68 |
# File 'lib/scorpion.rb', line 66 def execute( hunt ) fail "Not implemented" end |
#fetch(contract, *arguments, &block) ⇒ Object
Hunts for an object that satisfies the requested ‘contract`.
26 27 28 29 |
# File 'lib/scorpion.rb', line 26 def fetch( contract, *arguments, &block ) hunt = Hunt.new( self, contract, *arguments, &block ) execute hunt end |
#inject(target) ⇒ target
Inject the #target with all non-lazy dependencies.
47 48 49 50 51 52 |
# File 'lib/scorpion.rb', line 47 def inject( target ) hunt = Scorpion::Hunt.new self, nil hunt.inject target target end |
#new(object_class, *arguments, &block) ⇒ Scorpion::Object
Explicitly spawn an instance of #object_class and inject it’s dependencies.
58 59 60 61 |
# File 'lib/scorpion.rb', line 58 def new( object_class, *arguments, &block ) hunt = Hunt.new( self, object_class, *arguments, &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.
73 74 75 |
# File 'lib/scorpion.rb', line 73 def replicate( &block ) fail "Not implemented" end |
#reset ⇒ Object
Reset the hunting map and clear all dependencies.
83 84 |
# File 'lib/scorpion.rb', line 83 def reset end |
#spawn(hunt, object_class, *arguments, &block) ⇒ Scorpion::Object
Creates a new object and feeds it it’s dependencies.
36 37 38 39 40 41 42 |
# File 'lib/scorpion.rb', line 36 def spawn( hunt, object_class, *arguments, &block ) if object_class < Scorpion::Object object_class.spawn hunt, *arguments, &block else object_class.new *arguments, &block end end |