This file contains hidden or 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-validation' | |
| SCHEMA = Dry::Validation.Schema do | |
| configure do | |
| config.input_processor = :sanitizer | |
| def self.messages | |
| Dry::Validation::Messages.default.merge(en: { errors: { unique?: "oops not unique" }}) | |
| end |
This file contains hidden or 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
| ******************************************************************************** | |
| SEEDING 1000 users | |
| SEEDING 3000 tasks | |
| ******************************************************************************** | |
| ******************************************************************************** | |
| INSERTED 1000 users via ROM/Sequel | |
| INSERTED 3000 tasks via ROM/Sequel | |
| INSERTED 9000 tags via ROM/Sequel | |
| ******************************************************************************** |
This file contains hidden or 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
| class Users < ROM::Relation[:users] | |
| schema do | |
| attribute :id, Types::Serial | |
| attribute :name, Types::String | |
| associate do | |
| many :posts | |
| end | |
| end | |
| end |
This file contains hidden or 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 "rom-repository" | |
| require "rom-sql" | |
| config = ROM::Configuration.new(:sql, 'postgres://localhost/rom_repository') | |
| class Users < ROM::Relation[:sql] | |
| def by_id(id) | |
| where(id: id) | |
| end | |
| end |
This file contains hidden or 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 "rspec" | |
| require "json" | |
| require "dry-types" | |
| require "dry-validation" | |
| module Types | |
| include Dry::Types.module | |
| RegionCode = Types::Strict::String.constrained( | |
| format: /\A(au|nz|uk|ie)\z/, |
This file contains hidden or 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
| class UserSchema < Dry::Validation::Schema::Form | |
| key(:password).maybe(min_size: 6).confirmation | |
| key(:login).required(:bool?).when(:true?) do | |
| key(:password).success? | |
| end | |
| end | |
| schema = UserSchema.new |
This file contains hidden or 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-validation' | |
| require 'active_model' | |
| require 'benchmark' | |
| require 'thread_safe' | |
| schema = Class.new(Dry::Validation::Schema) do | |
| key(:name, &:filled?) | |
| key(:age) { |v| v.int? & v.gt?(18) } | |
| end.new |
This file contains hidden or 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
| Calculating ------------------------------------- | |
| type-safe users 273.000 i/100ms | |
| ar user models 257.000 i/100ms | |
| ------------------------------------------------- | |
| type-safe users 2.813k (± 1.7%) i/s - 14.196k | |
| ar user models 2.574k (±10.7%) i/s - 12.850k | |
| Comparison: | |
| type-safe users: 2812.7 i/s | |
| ar user models: 2574.2 i/s - 1.09x slower |
This file contains hidden or 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
| class Function | |
| attr_reader :name, :fn | |
| class Composed | |
| attr_reader :left, :right | |
| def initialize(left, right) | |
| @left = left | |
| @right = right | |
| end |
This file contains hidden or 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 'benchmark/ips' | |
| require 'compel' | |
| require 'dry-validation' | |
| require 'dry/validation/schema/form' | |
| params= { | |
| 'first_name' => 'Joaquim', | |
| 'birth_date' => '1989-0', | |
| 'address' => { | |
| 'line_one' => 'Lisboa', |