Sha256: 232bbb95c4c6c2d1cefe36386b9f63e347c0b756cc4b8004f3c09f0acffbc5b6

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Lite
  module Command
    class Base

      def self.inherited(base)
        super

        base.include Lite::Command::Internals::Callable
        base.include Lite::Command::Internals::Executable
        base.include Lite::Command::Internals::Resultable

        base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
          # eg: Users::ResetPassword::Fault
          class #{base}::Fault < Lite::Command::Fault; end
        RUBY

        FAULTS.each do |f|
          base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
            # eg: Users::ResetPassword::Noop < Users::ResetPassword::Fault
            class #{base}::#{f.capitalize} < #{base}::Fault; end
          RUBY
        end
      end

      attr_reader :context

      def initialize(context = {})
        @context = Lite::Command::Context.build(context)
      end

      private

      def additional_result_data
        {} # Define in your class to add additional info to result hash
      end

      def on_before_execution
        # Define in your class to run code before execution
      end

      def on_after_execution
        # Define in your class to run code after execution
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lite-command-2.0.1 lib/lite/command/base.rb
lite-command-2.0.0 lib/lite/command/base.rb