I’m writing a CLI tool, and want to use dry-types to check parameters/options.
I’d really like to include type hints in generated help, too. To that end, is there a nice way to get a human-readable summary of a type?
I tried #to_s
, but it’s not really what I’m after
string_type = Types::String
flavour_type = Types::String.enum('chocolate','strawberry','banana')
string_type.to_s
#=> "#<Dry::Types[Constrained<Nominal<String> rule=[type?(String)]>]>"
flavour_type.to_s
#=> "#<Dry::Types[Enum<Constrained<Nominal<String> rule=[type?(String) AND included_in?([\"chocolate\", \"strawberry\", \"banana\"])]> values={\"chocolate\", \"strawberry\", \"banana\"}>]>"
What I’m really after is:
string_type.to_s
#=> "String"
flavour_type.to_s
#=> "chocolate|strawberry|banana"