solnic on master
Merge pull request #131 from da… (compare)
module ApiTokens class Create include Dry::Transaction step :validate step :persist step :regenerate_token def validate(input) validation = ApiTokenSchema.call(input) validation.success? ? Success(input) : Failure(validation.errors) end def persist(input) api_token = ApiToken.new(input) api_token.save ? Success(api_token) : Failure(api_token.errors) end def regenerate_token(api_token) api_token.regenerate_token! Success(api_token) end end end
type_specsoption in dry-validation. The documentation page exists and explains that the syntax is experimental, but as far as I can tell it is not linked from the menu nor any of the other documentation pages. Yet the documentation page for input pre-processing, which has its own spot in the menu, makes use of the feature without explaining how it works. And there seems to be many quite long standing issues related to the feature. Please note that my intention is not to complain nor asking that somebody looks into all the issues, I'm just curious whether this feature is "official" or not.
is there a good ruby gem for transforming hash structures in a declarive, functional way. eg, consider this code I just wrote:
feed = ParsedFeedjiraFeed.new(url) Item.new( title: feed.title, author: feed.itunes_author, article_link: feed.url, mp3_link: feed.enclosure_url )
This is no big deal, because I’m just changing names in a flat hash, but you can imagine more complex cases where you are changing the actual structure (input is deeply nested, output is flat or nested in a different way, etc). what you want to do in these cases is simply specify a mapping from the input name paths to the output name paths using a dot syntax or similar. most functional langs make this kind of thing easy to do but i’d like to do the same in ruby.
separate question: is it possible to specify a custom error message when a constraint is violated. eg, consider:
URI = Types::Strict::String.constrained(format: URI::regexp)
when this is violated, the message includes the very long URI regexp. it would be nice if I could specify the message as “The string does not match URI::regexp”
in a way, dry-types targets data, not objects
would it be fair to say that in “the dry rb way,” object dependencies would be handled with the auto-injector, and data dependencies would be handles with dry-struct / dry-types?
and for producing nice messages there's
yeah, my question was specifically about the type error messages. it’s a small point, not really important.
dry-typesintentionally has no control over error messages