Class: Hypo::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/hypo/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, container, name = nil) ⇒ Component

Returns a new instance of Component.



7
8
9
10
11
12
13
# File 'lib/hypo/component.rb', line 7

def initialize(type, container, name = nil)
  @container = container
  @lifestyle = Transient.new(self)

  @type = type
  @name = name || type.name.gsub(/(.)([A-Z](?=[a-z]))/, '\1_\2').delete('::').downcase.to_sym
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



5
6
7
# File 'lib/hypo/component.rb', line 5

def container
  @container
end

#lifestyleObject (readonly)

Returns the value of attribute lifestyle.



5
6
7
# File 'lib/hypo/component.rb', line 5

def lifestyle
  @lifestyle
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/hypo/component.rb', line 5

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/hypo/component.rb', line 5

def type
  @type
end

Instance Method Details

#dependenciesObject



19
20
21
# File 'lib/hypo/component.rb', line 19

def dependencies
  @type.instance_method(:initialize).parameters.map { |p| @container.resolve(p[1]) }
end

#instanceObject



15
16
17
# File 'lib/hypo/component.rb', line 15

def instance
  @lifestyle.instance
end

#use_lifestyle(lifestyle) ⇒ Object Also known as: using_lifestyle



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

def use_lifestyle(lifestyle)
  @lifestyle = lifestyle.new(self)
end