Sha256: fe46a8a9dd77efce2779e9c0f79e94d5917d7436daf021d02018e0be4466b807
Contents?: true
Size: 912 Bytes
Versions: 11
Compression:
Stored size: 912 Bytes
Contents
require 'dry/struct' require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Schema.define do create_table :users do |table| table.column :name, :string table.column :age, :integer end end class ARUser < ActiveRecord::Base self.table_name = :users end module Types include Dry::Types.module end class DryStructUser < Dry::Struct attribute :id, Types::Form::Int attribute :name, Types::Strict::String.constrained(size: 3..64) attribute :age, Types::Form::Int.constrained(gt: 18) end puts ARUser.new(id: 1, name: 'Jane', age: '21').inspect puts DryStructUser.new(id: 1, name: 'Jane', age: '21').inspect Benchmark.ips do |x| x.report('active record') { ARUser.new(id: 1, name: 'Jane', age: '21') } x.report('dry-struct') { DryStructUser.new(id: 1, name: 'Jane', age: '21') } x.compare! end
Version data entries
11 entries across 11 versions & 1 rubygems