Sha256: 30ece866f17c6fa630e9c4e88a39dedfaa3680bc3ee474722f4d204ebf1550bb

Contents?: true

Size: 713 Bytes

Versions: 43

Compression:

Stored size: 713 Bytes

Contents

# frozen_string_literal: true

module Ree::Contracts
  module ArgContracts
    class RespondTo
      extend Ree::Contracts::ArgContracts::Squarable

      def initialize(*method_names)
        @method_names = method_names
      end

      def valid?(value)
        get_unrespond_list(value).empty?
      end

      def to_s
        "RespondTo#{method_names.inspect}"
      end

      def message(value, name, lvl = 1)
        unrespond_list = get_unrespond_list(value)
        "expected to respond to #{unrespond_list.inspect}}"
      end

      private
        def get_unrespond_list(obj)
          @method_names.reject do |method|
            obj.respond_to?(method)
          end
        end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
ree-1.1.0 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.47 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.46 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.45 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.44 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.43 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.42 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.41 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.40 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.39 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.38 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.37 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.36 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.35 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.34 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.33 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.32 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.31 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.30 lib/ree/contracts/arg_contracts/respond_to.rb
ree-1.0.29 lib/ree/contracts/arg_contracts/respond_to.rb