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