Sha256: 89016ceda70a5801413f0cb409143dfe966f968d5db5d1ebaec762b9f646e445

Contents?: true

Size: 886 Bytes

Versions: 7

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

module Lite
  module Command
    class Complex

      class << self

        def call(*args)
          klass = new(*args)
          raise Lite::Command::NotImplementedError unless klass.respond_to?(:execute)

          klass.call
          klass
        end

        def execute(*args)
          klass = call(*args)
          klass.result
        end

      end

      attr_reader :result

      def initialize(*args)
        @args = args
      end

      def call
        raise Lite::Command::NotImplementedError unless defined?(execute)
        return @result if called?

        @called = true
        @result = execute
      end

      def called?
        @called ||= false
      end

      def recall!
        @called = false
        %i[cache errors].each { |mixin| send(mixin).clear if respond_to?(mixin) }
        call
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lite-command-1.1.1 lib/lite/command/complex.rb
lite-command-1.1.0 lib/lite/command/complex.rb
lite-command-1.0.10 lib/lite/command/complex.rb
lite-command-1.0.9 lib/lite/command/complex.rb
lite-command-1.0.8 lib/lite/command/complex.rb
lite-command-1.0.7 lib/lite/command/complex.rb
lite-command-1.0.6 lib/lite/command/complex.rb