Created
February 22, 2016 10:17
-
-
Save gmile/e61e1f4f83cc8c187059 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dry-data' | |
module Types | |
end | |
Dry::Data.configure do |config| | |
config.namespace = Types | |
end | |
Dry::Data.finalize | |
class Product < Dry::Data::Struct | |
attribute :title, Types::Strict::String | |
attribute :price, Types::Coercible::Decimal | |
attribute :vendor_id, Types::Coercible::Int | |
end | |
[ | |
{ title: 'Apple', price: '5.0', vendor_id: '185' }, | |
{ title: 'Orange', price: '15.0', vendor_id: '14' }, | |
{ title: 'Car', price: '150000.0', vendor_id: '1' } | |
].each do |attributes| | |
puts Product.new(attributes).inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment