Class: Hypo::Component
- Inherits:
-
Object
- Object
- Hypo::Component
- Defined in:
- lib/hypo/component.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, container) ⇒ Component
constructor
A new instance of Component.
- #instance ⇒ Object
Constructor Details
#initialize(type, container) ⇒ Component
Returns a new instance of Component.
5 6 7 8 9 |
# File 'lib/hypo/component.rb', line 5 def initialize(type, container) @type = type @name = type.name.gsub(/(.)([A-Z](?=[a-z]))/,'\1_\2').delete('::').downcase.to_sym @container = container end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/hypo/component.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/hypo/component.rb', line 3 def type @type end |
Instance Method Details
#instance ⇒ Object
11 12 13 14 15 16 |
# File 'lib/hypo/component.rb', line 11 def instance dependencies = @type.instance_method(:initialize).parameters.map{|p| @container.resolve(p[1])} @instance = @type.new(*dependencies) if @instance.nil? @instance end |