Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'dry-struct'
module Types
include Dry::Types.module
end
class Button < Dry::Struct
attribute :text, Types::String
end
class Markup < Dry::Struct
attribute :keyboard, Types::Strict::Array.member(Types::Strict::Array.member(Button))
end
mark = Markup.new(
keyboard: [
[{ text: '1st button text' }, { text: '2nd button text' }],
[{ text: '3rd button text' }]
]
)
=> #<Markup keyboard=[[#<Button text="1st button text">, #<Button text="2nd button text">], [#<Button text="3rd button text">]]>
Markup.schema
=> {:keyboard=>#<Dry::Types::Constrained type=#<Dry::Types::Array::Member primitive=Array options={:member=>#<Dry::Types::Constrained type=#<Dry::Types::Array::Member primitive=Array options={:member=>Button} meta={}> options={:rule=>#<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#type?> options={:args=>[Array]}>} rule=#<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#type?> options={:args=>[Array]}>>} meta={}> options={:rule=>#<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#type?> options={:args=>[Array]}>} rule=#<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#type?> options={:args=>[Array]}>>}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.