Module: Scorpion::Object
Overview
Identifies objects that are injected by scorpions that inject hunted dependencies.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.infest(base) ⇒ Object
Infest the object with a scoprion and prepare it to be fed.
- .prepended(base) ⇒ Object
Instance Method Summary collapse
Methods included from Method
Class Method Details
.infest(base) ⇒ Object
Infest the object with a scoprion and prepare it to be fed.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/scorpion/object.rb', line 36 def self.infest( base ) base.extend Scorpion::Object::ClassMethods if base.is_a? Class base.class_exec do # Create a new instance of this class with all non-lazy dependencies # satisfied. # @param [Hunt] hunt that this instance will be used to satisfy. def self.spawn( hunt, *args, **dependencies, &block ) object = if dependencies.any? new( *args, **dependencies, &block ) else new( *args, &block ) end object.send :scorpion=, hunt.scorpion # Go hunt for dependencies that are not lazy and initialize the # references. hunt.inject object object end end base.subclasses.each do |sub| infest( sub ) unless sub < Scorpion::Object end end end |
.prepended(base) ⇒ Object
74 75 76 77 |
# File 'lib/scorpion/object.rb', line 74 def self.prepended( base ) infest( base ) super end |
Instance Method Details
#injected_attributes ⇒ Object
17 18 19 |
# File 'lib/scorpion/object.rb', line 17 def injected_attributes self.class.injected_attributes end |