Sha256: 5835143b88b0a7b5332f1d4be99997b29f4c47431ac947e2530e8df03b32b3f5

Contents?: true

Size: 1.82 KB

Versions: 16

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

module AASM
  module Core
    module Invokers
      ##
      # Base concrete invoker class which contain basic
      # invoking and logging definitions
      class BaseInvoker
        attr_reader :failures, :subject, :record, :args, :result

        ##
        # Initialize a new concrete invoker instance.
        # NOTE that concrete invoker must be used per-subject/record
        #      (one instance per subject/record)
        #
        # ==Options:
        #
        # +subject+ - invoking subject comparable with this invoker
        # +record+  - invoking record
        # +args+    - arguments which will be passed to the callback

        def initialize(subject, record, args)
          @subject = subject
          @record = record
          @args = args
          @result = false
          @failures = []
        end

        ##
        # Collect failures to a specified buffer
        #
        # ==Options:
        #
        # +failures+ - failures buffer to collect failures

        def with_failures(failures_buffer)
          @failures = failures_buffer
          self
        end

        ##
        # Execute concrete invoker, log the error and return result

        def invoke
          return unless may_invoke?
          log_failure unless invoke_subject
          result
        end

        ##
        # Check if concrete invoker may be invoked for a specified subject

        def may_invoke?
          raise NoMethodError, '"#may_invoke?" is not implemented'
        end

        ##
        # Log failed invoking

        def log_failure
          raise NoMethodError, '"#log_failure" is not implemented'
        end

        ##
        # Execute concrete invoker

        def invoke_subject
          raise NoMethodError, '"#invoke_subject" is not implemented'
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
aasm-5.5.0 lib/aasm/core/invokers/base_invoker.rb
aasm-5.4.0 lib/aasm/core/invokers/base_invoker.rb
aasm-5.3.1 lib/aasm/core/invokers/base_invoker.rb
aasm-5.3.0 lib/aasm/core/invokers/base_invoker.rb
aasm-5.2.0 lib/aasm/core/invokers/base_invoker.rb
aasm-5.1.1 lib/aasm/core/invokers/base_invoker.rb
aasm-5.1.0 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.8 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.7 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.6 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.5 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.4 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.3 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.2 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.1 lib/aasm/core/invokers/base_invoker.rb
aasm-5.0.0 lib/aasm/core/invokers/base_invoker.rb