Module: BatchKit::ActsAsSequence::ClassMethods

Defined in:
lib/batch-kit/framework/acts_as_sequence.rb

Overview

Define methods to be added to the class that includes this module.

Instance Method Summary collapse

Instance Method Details

#desc(desc) ⇒ Object

Captures a description for the following sequence definition.

Parameters:

  • desc (String)

    The description to associate with the next sequence, job, or task that is defined.



36
37
38
# File 'lib/batch-kit/framework/acts_as_sequence.rb', line 36

def desc(desc)
    @__desc__ = desc
end

#sequence(sequence_method = nil, sequence_opts = @__desc__, &body) ⇒ Object

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.

Parameters:

  • sequence_method (Symbol) (defaults to: nil)

    The name of an existing method that is to be the sequence entry point.

  • sequence_opts (Hash) (defaults to: @__desc__)

    Options that affect the sequence definition.

Options Hash (sequence_opts):

  • :method_name (Symbol)

    The name to be assigned to the sequence method created from the supplied block. Default is :execute.

  • :description (String)

    A description for the sequence.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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

#sequence_definitionObject Also known as: definition

Returns The Sequence::Definition object used to hold attributes of this sequence.

Returns:

  • The Sequence::Definition object used to hold attributes of this sequence.



26
27
28
# File 'lib/batch-kit/framework/acts_as_sequence.rb', line 26

def sequence_definition
    @__sequence__
end