Sha256: 7aac51a97027c9a339183bda5549b12eba980da695bf01afbdc079ee865b33c5

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module BusinessFlow
  # include BusinessFlow::Base in any object to get a flow!
  # :reek:ModuleInitialize
  module Base
    def self.included(klass)
      klass.include(DSL)
      klass.prepend(InstanceMethods)
    end

    # "Helper" methods which we put on an object to provide some default
    # behavior.
    module InstanceMethods
      attr_reader :parameter_object
      private :parameter_object

      # Initialize is here so that we can set the parameter object, and then
      # allow our "parent" class to handle any additional initialization that
      # it needs to do.
      def initialize(parameter_object)
        @parameter_object = parameter_object
        catch(:halt_step) do
          super()
        end
      end

      def call
        # If our initialization process set any errors, return
        return if errors.any? || invalid?
        if defined?(super)
          catch(:halt_step) do
            super
          end
        else
          ::BusinessFlow::DefaultStepExecutor.new(self.class.step_queue, self)
                                             .call
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
business_flow-0.7.0 lib/business_flow/base.rb
business_flow-0.6.0 lib/business_flow/base.rb