Skip to content

Instantly share code, notes, and snippets.

@gmile
Created February 22, 2016 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmile/e61e1f4f83cc8c187059 to your computer and use it in GitHub Desktop.
Save gmile/e61e1f4f83cc8c187059 to your computer and use it in GitHub Desktop.
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