Module: Conject

Defined in:
lib/conject.rb,
lib/conject/version.rb,
lib/conject/utilities.rb,
lib/conject/class_finder.rb,
lib/conject/object_context.rb,
lib/conject/object_factory.rb,
lib/conject/composition_error.rb,
lib/conject/object_definition.rb,
lib/conject/dependency_resolver.rb

Defined Under Namespace

Modules: Utilities Classes: ClassFinder, CompositionError, DependencyResolver, ObjectContext, ObjectDefinition, ObjectFactory

Constant Summary collapse

VERSION =
"0.1.8"

Class Method Summary collapse

Class Method Details

.create_object_context(parent_context, object_factory = nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/conject.rb', line 35

def self.create_object_context(parent_context, object_factory=nil)
  object_factory ||= default_object_factory
  ObjectContext.new(
    :parent_context => parent_context,
    :object_factory => object_factory
  )
end

.default_object_contextObject

Provide access to the default ObjectContext.

This context is created on first use, and can serve as the root of all other ObjectContexts.



23
24
25
# File 'lib/conject.rb', line 23

def self.default_object_context
  @default_object_context ||= create_object_context(nil)
end

.default_object_factoryObject



27
28
29
30
31
32
33
# File 'lib/conject.rb', line 27

def self.default_object_factory
  class_finder = ClassFinder.new
  @default_object_factory ||=  ObjectFactory.new(
    :class_finder => class_finder,
    :dependency_resolver => DependencyResolver.new(:class_finder => class_finder)
  )
end

.install_object_context(target, context) ⇒ Object



43
44
45
# File 'lib/conject.rb', line 43

def self.install_object_context(target, context)
  target.instance_variable_set(:@_conject_object_context, context)
end

.override_object_context_with(object_context, &block) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/conject.rb', line 47

def self.override_object_context_with(object_context, &block)
  Thread.current[:_overriding_conject_object_context] = object_context
  begin
    block.call
  ensure
    Thread.current[:_overriding_conject_object_context] = nil
  end
end