Class: Hypo::Instance

Inherits:
Object
  • Object
show all
Includes:
LifetimeFriendly, ScopeFriendly
Defined in:
lib/hypo/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LifetimeFriendly

#use_lifetime

Methods included from ScopeFriendly

#bind_to, #scope

Constructor Details

#initialize(object, container, name) ⇒ Instance

Returns a new instance of Instance.

Raises:



11
12
13
14
15
16
17
18
# File 'lib/hypo/instance.rb', line 11

def initialize(object, container, name)
  raise ContainerError, 'Registered object should have a name' if name.nil?

  @object = object
  @container = container
  @lifetime = container.lifetimes[:transient]
  @name = name
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



9
10
11
# File 'lib/hypo/instance.rb', line 9

def container
  @container
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/hypo/instance.rb', line 9

def name
  @name
end

#objectObject (readonly)

Returns the value of attribute object.



9
10
11
# File 'lib/hypo/instance.rb', line 9

def object
  @object
end

Instance Method Details

#instance(attrs = nil) ⇒ Object



20
21
22
# File 'lib/hypo/instance.rb', line 20

def instance(attrs = nil)
  @lifetime.instance(self)
end