Sha256: 9d1b76d22e1a38ab18cafbb7285bb52455b697304fe4bbe8b9c3bbaad460454b

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

# frozen_string_literal: true

module Trailblazer
  class Finder
    module Activity
      class PrepareEntity < Trailblazer::Activity::Railway
        def validate_entity(ctx, **)
          ctx.dig(:options,:entity) || ctx.dig(:config,:entity)
        end

        def invalid_entity_error(ctx, **)
          (ctx[:errors] ||= []) << {entity: "Invalid entity specified"}
        end

        def set_entity(ctx, **)
          ctx[:entity] = ctx.dig(:options,:entity) || instance_eval(&ctx[:config][:entity])
        end

        step (:validate_entity)
        fail (:invalid_entity_error)
        step (:set_entity)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trailblazer-finder-0.10.0 lib/trailblazer/finder/activity/prepare_entity.rb