module BatchKit::ActsAsSequence::ClassMethods
Define methods to be added to the class that includes this module.
Public Instance Methods
Captures a description for the following sequence definition.
@param desc [String] The description to associate with the next
sequence, job, or task that is defined.
# File lib/batch-kit/framework/acts_as_sequence.rb, line 36 def desc(desc) @__desc__ = desc end
Defines the method that is used to run this job. This may be an existing method, in which case the name of the method must be passed as the first argument. Alternatively, a block may be supplied, which will be used to create the job method.
@param sequence_method [Symbol] The name of an existing method that is
to be the sequence entry point.
@param sequence_opts [Hash] Options that affect the sequence definition. @option sequence_opts [Symbol] :method_name The name to be assigned to
the sequence method created from the supplied block. Default is :execute.
@option sequence_opts [String] :description A description for the sequence.
# File lib/batch-kit/framework/acts_as_sequence.rb, line 54 def sequence(sequence_method = nil, sequence_opts = @__desc__, &body) # If called as an accessor, just return the @__sequence__ if sequence_method || sequence_opts || body unless sequence_method.is_a?(Symbol) sequence_opts = sequence_method sequence_method = (sequence_opts && sequence_opts.is_a?(Hash) && sequence_opts[:method_name]) || :execute end sequence_desc = nil if sequence_opts.is_a?(Hash) sequence_desc = @__desc__ elsif sequence_opts.is_a?(String) sequence_desc = sequence_opts sequence_opts = {} elsif sequence_opts.nil? sequence_opts = {} end @__desc__ = nil # Define sequence method if a body block was supplied define_method(sequence_method, &body) if body opts = sequence_opts.clone opts[:description] = sequence_desc unless opts[:description] opts[:method_name] = sequence_method # The @__sequence__ instance variable is crated when this module is included @__sequence__.set_from_options(opts) end @__sequence__ end
@return The Sequence::Definition
object used to hold attributes of this
sequence.
# File lib/batch-kit/framework/acts_as_sequence.rb, line 26 def sequence_definition @__sequence__ end