Module: Scorpion::Object

Includes:
Method
Included in:
Rails::Nest
Defined in:
lib/scorpion/object.rb

Overview

Identifies objects that are injected by scorpions that inject hunted dependencies.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Method

#scorpion, #scorpion_hunt

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
# 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, &block )
        object = new( *args, &block )
        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



67
68
69
70
# File 'lib/scorpion/object.rb', line 67

def self.prepended( base )
  infest( base )
  super
end

Instance Method Details

#injected_attributesObject



17
18
19
# File 'lib/scorpion/object.rb', line 17

def injected_attributes
  self.class.injected_attributes
end