Sha256: e0ed2e0fca6ac1860c6d5b8748dcd24fb2f1b4c9d2c3965159c10d80078340d0

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require_relative "arguments/null_arguments"

module ConvenientService
  module Support
    class Arguments
      ##
      # @!attribute [r] args
      #   @return [Array]
      #
      attr_reader :args

      ##
      # @!attribute [r] kwargs
      #   @return [Hash]
      #
      attr_reader :kwargs

      ##
      # @!attribute [r] block
      #   @return [Proc]
      #
      attr_reader :block

      ##
      # @param args [Array<Object>]
      # @param kwargs [Hash{Symbol => Object}]
      # @param block [Proc, nil]
      # @return [void]
      #
      def initialize(*args, **kwargs, &block)
        @args = args
        @kwargs = kwargs
        @block = block
      end

      class << self
        ##
        # @return [ConvenientService::Support::Arguments::NullArguments]
        #
        def null_arguments
          @null_arguments ||= Support::Arguments::NullArguments.new
        end
      end

      ##
      # @return [Boolean]
      #
      def null_arguments?
        false
      end

      ##
      # @return [Booleam]
      #
      def any?
        return true if args.any?
        return true if kwargs.any?
        return true if block

        false
      end

      ##
      # @return [Booleam]
      #
      def none?
        !any?
      end

      ##
      # @param other [Object]
      # @return [Boolean]
      #
      def ==(other)
        return unless other.instance_of?(self.class)

        return false if args != other.args
        return false if kwargs != other.kwargs
        return false if block != other.block

        true
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/support/arguments.rb
convenient_service-0.19.0 lib/convenient_service/support/arguments.rb
convenient_service-0.18.0 lib/convenient_service/support/arguments.rb
convenient_service-0.17.0 lib/convenient_service/support/arguments.rb
convenient_service-0.16.0 lib/convenient_service/support/arguments.rb
convenient_service-0.15.0 lib/convenient_service/support/arguments.rb
convenient_service-0.14.0 lib/convenient_service/support/arguments.rb
convenient_service-0.13.0 lib/convenient_service/support/arguments.rb
convenient_service-0.12.0 lib/convenient_service/support/arguments.rb