Class: Hypo::Component
- Inherits:
-
Object
- Object
- Hypo::Component
- Defined in:
- lib/hypo/component.rb
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#lifestyle ⇒ Object
readonly
Returns the value of attribute lifestyle.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #dependencies ⇒ Object
-
#initialize(type, container, name = nil) ⇒ Component
constructor
A new instance of Component.
- #instance ⇒ Object
- #use_lifestyle(lifestyle) ⇒ Object (also: #using_lifestyle)
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
#container ⇒ Object (readonly)
Returns the value of attribute container.
5 6 7 |
# File 'lib/hypo/component.rb', line 5 def container @container end |
#lifestyle ⇒ Object (readonly)
Returns the value of attribute lifestyle.
5 6 7 |
# File 'lib/hypo/component.rb', line 5 def lifestyle @lifestyle end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/hypo/component.rb', line 5 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/hypo/component.rb', line 5 def type @type end |
Instance Method Details
#dependencies ⇒ Object
19 20 21 |
# File 'lib/hypo/component.rb', line 19 def dependencies @type.instance_method(:initialize).parameters.map { |p| @container.resolve(p[1]) } end |
#instance ⇒ Object
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 |