constructor_type :schemastyle :P )
optional(:group_ids, [:int]).value(:array?)but am having trouble figuring out how the element validation would work. Any advice?
Hi guys :) I am learning (and trying to implement) dry-transaction, I am going thru the Introduction and found this:
Each operation shouldn’t accumulate state, instead it should receive an input and return an output without causing any side-effects.
What do you mean by that? Especially this part
without causing any side-effects?
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.