lib/attr/gather/workflow/dsl.rb in attr-gather-1.2.0 vs lib/attr/gather/workflow/dsl.rb in attr-gather-1.2.1
- old
+ new
@@ -14,11 +14,11 @@
#
# @param task_name [Symbol] the name of the task
#
# @example
# class EnhanceUserProfile
- # extend Attr::Gather::Workflow
+ # include Attr::Gather::Workflow
#
# # ...
#
# task :fetch_database_info do |t|
# t.depends_on = []
@@ -40,10 +40,60 @@
yield conf
tasks << Hash[name: task_name, **opts, **conf.to_h]
self
end
+ # Defines a task with name and options
+ #
+ # @param task_name [Symbol] the name of the task
+ #
+ # @example
+ # class EnhanceUserProfile
+ # include Attr::Gather::Workflow
+ #
+ # # ...
+ #
+ # fetch :user_info do |t|
+ # t.depends_on = [:fetch_gravatar_info]
+ # end
+ # end
+ #
+ # Calling `fetch` will yield a task object which you can configure like
+ # a PORO. Tasks will be registered for execution in the workflow.
+ #
+ # @yield [Attr::Gather::Workflow::Task] A task to configure
+ #
+ # @api public
+ def fetch(task_name, opts = EMPTY_HASH)
+ task(task_name, opts)
+ end
+
+ # Defines a task with name and options
+ #
+ # @param task_name [Symbol] the name of the task
+ #
+ # @example
+ # class EnhanceUserProfile
+ # include Attr::Gather::Workflow
+ #
+ # # ...
+ #
+ # step :fetch_user_info do |t|
+ # t.depends_on = [:email_info]
+ # end
+ # end
+ #
+ # Calling `step` will yield a task object which you can configure like
+ # a PORO. Tasks will be registered for execution in the workflow.
+ #
+ # @yield [Attr::Gather::Workflow::Task] A task to configure
+ #
+ # @api public
+ def step(task_name, opts = EMPTY_HASH)
+ task(task_name, opts)
+ end
+
# Defines a container for task dependencies
#
# Using a container makes it easy to re-use workflows with different
# data sources. Say one workflow was required to use a legacy DB, and
# one wanted to use a new DB. Using a container makes it easy to
@@ -53,11 +103,11 @@
# LegacySystem = Dry::Container.new.tap do |c|
# c.register(:database) { Sequel.connect('sqlite://legacy.db')
# end
#
# class EnhanceUserProfile
- # extend Attr::Gather::Workflow
+ # include Attr::Gather::Workflow
#
# container LegacySystem
# end
#
# @param cont [Dry::Container] the Dry::Container to use
@@ -77,11 +127,11 @@
# yuo could build and aggregator that prioritizes the
# values of some tasks over others.
#
# @example
# class EnhanceUserProfile
- # extend Attr::Gather::Workflow
+ # include Attr::Gather::Workflow
#
# aggregator :deep_merge
# end
#
# @param agg [#call] the aggregator to use
@@ -117,11 +167,11 @@
# optional(:email).filled(:str?, format?: /@/)
# end
# end
#
# class EnhanceUserProfile
- # extend Attr::Gather::Workflow
+ # include Attr::Gather::Workflow
#
# # Any of the key/value pairs that had validation errors will be
# # filtered from the output.
# filter :contract, UserContract.new
# end
@@ -149,10 +199,10 @@
# This serves as a convenience method for defining a contract filter.
#
# @example
#
# class EnhanceUserProfile
- # extend Attr::Gather::Workflow
+ # include Attr::Gather::Workflow
#
# # Any of the key/value pairs that had validation errors will be
# # filtered from the output.
# filter_with_contract do
# params do