lib/attr/gather/workflow/dsl.rb in attr-gather-1.4.0 vs lib/attr/gather/workflow/dsl.rb in attr-gather-1.5.1

- old
+ new

@@ -36,11 +36,11 @@ # # @api public def task(task_name, opts = EMPTY_HASH) conf = OpenStruct.new yield conf - tasks << Hash[name: task_name, **opts, **conf.to_h] + tasks << ({ name: task_name, **opts, **conf.to_h }) self end # Defines a task with name and options # @@ -132,16 +132,25 @@ # include Attr::Gather::Workflow # # aggregator :deep_merge # end # + # @example + # class EnhanceUserProfile + # include Attr::Gather::Workflow + # + # aggregator MyCustomAggregator + # end + # # @param agg [#call] the aggregator to use # # @api public def aggregator(agg = nil, opts = EMPTY_HASH) @aggregator = if agg.nil? && !defined?(@aggregator) Aggregators.default + elsif agg.respond_to?(:new) + agg.new(filter: filter, **opts) elsif agg Aggregators.resolve(agg, filter: filter, **opts) else @aggregator end @@ -220,10 +229,10 @@ # @return [Dry::Validation::Contract,NilClass] # @see https://dry-rb.org/gems/dry-validation # # @api public def filter_with_contract(arg = nil, &blk) - contract = block_given? ? build_inline_contract_filter(&blk) : arg + contract = blk ? build_inline_contract_filter(&blk) : arg filter(:contract, contract) end private