Sha256: 6d73f241585c726390acc04845c206efe57202acabb40d3ab0d22467ac152589

Contents?: true

Size: 687 Bytes

Versions: 1

Compression:

Stored size: 687 Bytes

Contents

# frozen_string_literal: true

module Trailblazer
  class Finder
    module Activities
      class PrepareAdapter < Trailblazer::Activity::Railway
        def set_adapter(ctx, **)
          ctx[:adapter] = ctx.dig(:config, :adapter) || "Basic"
        end

        def validate_adapter(_ctx, adapter:, **)
          ORM_ADAPTERS.(adapter.to_s)
        end

        def invalid?(_e, (ctx, _flow_options), **_circuit_options)
          (ctx[:errors] ||= []) << {adapter: "The specified adapter are invalid"}
        end

        step :set_adapter
        step Rescue(Dry::Types::ConstraintError, handler: :invalid?) {
          step :validate_adapter
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trailblazer-finder-0.91.0 lib/trailblazer/finder/activities/prepare_adapter.rb