Created
May 23, 2017 15:01
-
-
Save ivanovaleksey/782a7843ce213254a8843e3326b5bc4f 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-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