Method: Castkit::Ext::DataObject::Contract#from_contract
- Defined in:
- lib/castkit/ext/data_object/contract.rb
#from_contract(contract) ⇒ Class<Castkit::DataObject>
Constructs a new Castkit::DataObject class from a given contract.
This method is the inverse of ‘.to_contract` and provides a way to generate a DataObject from an existing contract definition.
69 70 71 72 73 74 75 |
# File 'lib/castkit/ext/data_object/contract.rb', line 69 def from_contract(contract) Class.new(Castkit::DataObject).tap do |klass| contract.attributes.each_value do |attr| klass.attribute(attr.field, attr.type, **attr.) end end end |