Skip to content

Instantly share code, notes, and snippets.

@ivanovaleksey
Created May 23, 2017 15:01
Show Gist options
  • Save ivanovaleksey/782a7843ce213254a8843e3326b5bc4f to your computer and use it in GitHub Desktop.
Save ivanovaleksey/782a7843ce213254a8843e3326b5bc4f to your computer and use it in GitHub Desktop.
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