Sha256: cadef9f69b4a331f20399b494237d20081c1dacd2cf41123e78051c7e89ec1fa

Contents?: true

Size: 959 Bytes

Versions: 1

Compression:

Stored size: 959 Bytes

Contents

module Speculation
  # Collection of predicate methods used within Speculation.
  # These may appear as the value for the `:pred` key in the return value of
  # `Speculation.explain_data`.
  module Predicates
    def self.hash?(x)
      x.respond_to?(:store) && x.respond_to?(:key?) && x.respond_to?(:[])
    end

    def self.array?(x)
      x.respond_to?(:at) && x.respond_to?(:[])
    end

    def self.collection?(xs)
      xs.respond_to?(:each)
    end

    def self.distinct?(xs)
      seen = Set[]

      xs.each do |x|
        if seen.include?(x)
          return false
        else
          seen << x
        end
      end

      true
    end

    def self.count_eq?(count, coll)
      coll.count == count
    end

    def self.count_between?(min_count, max_count, coll)
      coll.count.between?(min_count, max_count)
    end

    def self.key?(hash, key)
      hash.key?(key)
    end

    def self.empty?(coll)
      coll.empty?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
speculation-0.4.2 lib/speculation/predicates.rb