Sha256: dd3ab96a682f1a0131de21f303bf989a406c71d8692f91184ab0bec8a0807886

Contents?: true

Size: 1007 Bytes

Versions: 4

Compression:

Stored size: 1007 Bytes

Contents

module Light
  module Services
    class Base
      # Includes
      include Light::Services::Parameters
      include Light::Services::Callbacks

      # Getters
      attr_reader :errors, :warnings

      def initialize(args = {})
        @args = args

        initialize_params
        initialize_outputs

        @errors   = Light::Services::Messages.new
        @warnings = Light::Services::Messages.new
      end

      def call
        run_service
      end

      def success?
        errors.blank?
      end

      def any_warnings?
        warnings.any?
      end

      class << self
        def call(args = {})
          service = new(args)
          service.call
          service
        end

        alias run call
      end

      private

      # Getters
      attr_reader :args

      def run_service
        run_callbacks(:before)
        run if success?
        run_callbacks(:after) if success?
        run_callbacks(:finally, break: false)
        success?
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
light-services-0.4.0 lib/light/services/base.rb
light-services-0.3.0 lib/light/services/base.rb
light-services-0.2.0 lib/light/services/base.rb
light-services-0.1.0 lib/light/services/base.rb