Sha256: f92f288e7f4f674bf0683e25d99f920857c1a17657526d655eb20dcd023d4c86

Contents?: true

Size: 570 Bytes

Versions: 48

Compression:

Stored size: 570 Bytes

Contents

# frozen_string_literal: true

module Ree::Contracts
  module ArgContracts
    class SubclassOf
      extend Ree::Contracts::ArgContracts::Squarable
      include Ree::Contracts::Truncatable

      attr_reader :klass

      def initialize(klass)
        @klass = klass
      end

      def valid?(value)
        value.is_a?(Class) && value < klass
      end

      def to_s
        "SubclassOf[#{klass.inspect}]"
      end

      def message(value, name, lvl = 1)
        "expected #{truncate(self.to_s, 30)}, got #{truncate(value.inspect)}"
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
ree-1.0.7 lib/ree/contracts/arg_contracts/subclass_of.rb
ree-1.0.6 lib/ree/contracts/arg_contracts/subclass_of.rb
ree-1.0.5 lib/ree/contracts/arg_contracts/subclass_of.rb
ree-1.0.4 lib/ree/contracts/arg_contracts/subclass_of.rb
ree-1.0.3 lib/ree/contracts/arg_contracts/subclass_of.rb
ree-1.0.2 lib/ree/contracts/arg_contracts/subclass_of.rb
ree-1.0.1 lib/ree/contracts/arg_contracts/subclass_of.rb
ree-1.0.0 lib/ree/contracts/arg_contracts/subclass_of.rb