Sha256: 3841fcf295cbf2dedc6f0ac86fcc8d3b52a139697156c546ea88ffe6398eeab7

Contents?: true

Size: 648 Bytes

Versions: 2

Compression:

Stored size: 648 Bytes

Contents

# frozen_string_literal: true

module LightServiceExt
  class ApplicationAction
    extend LightService::Action

    class << self
      def add_params(ctx, **params)
        add_to_context(ctx, :params, **params)
      end

      def add_errors(ctx, **errors)
        add_to_context(ctx, :errors, **errors)

        ctx.fail_and_return! if ctx[:errors].present?
      end

      private

      def add_to_context(ctx, key, **args)
        return if ctx.nil?

        ctx[key].merge!(args.dup)
        nil
      end
    end

    def self.inherited(base)
      base.singleton_class.prepend AroundActionExecuteExtension
      super
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
light-service-ext-0.1.1 lib/light-service-ext/application_action.rb
light-service-ext-0.1.0 lib/light-service-ext/application_action.rb