Class: SpinningWheel::Fabric
- Inherits:
-
Object
- Object
- SpinningWheel::Fabric
- Defined in:
- lib/spinning_wheel/fabric.rb
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(name:, class_name:, &block) ⇒ Fabric
constructor
A new instance of Fabric.
Constructor Details
#initialize(name:, class_name:, &block) ⇒ Fabric
Returns a new instance of Fabric.
6 7 8 9 10 |
# File 'lib/spinning_wheel/fabric.rb', line 6 def initialize(name:, class_name:, &block) @name = name @class_name = class_name @block = block end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
4 5 6 |
# File 'lib/spinning_wheel/fabric.rb', line 4 def class_name @class_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/spinning_wheel/fabric.rb', line 4 def name @name end |
Instance Method Details
#build ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/spinning_wheel/fabric.rb', line 12 def build @klass = @class_name.constantize attributes = DSL.run(@block) parameters = @klass.instance_method(:initialize).parameters required_parametes = [] parameters.each do |parameter| if parameter[0] == :req required_parametes << parameter[1] end end if required_parametes == attributes.keys @klass.new(*attributes.values) else @klass.new(**attributes) end end |