class Speculation::OrSpec

@private

Constants

S

This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.

Attributes

id[R]

Public Class Methods

new(named_specs, gen = nil) click to toggle source
# File lib/speculation/spec/or_spec.rb, line 15
def initialize(named_specs, gen = nil)
  @id = SecureRandom.uuid
  @named_specs = named_specs
  @keys = named_specs.keys
  @preds = preds = named_specs.values
  @gen = gen

  @delayed_specs = Concurrent::Delay.new do
    preds.map { |spec| S.send(:specize, spec) }
  end
end

Public Instance Methods

conform(value) click to toggle source
# File lib/speculation/spec/or_spec.rb, line 27
def conform(value)
  @delayed_specs.value!.each_with_index do |spec, index|
    conformed = spec.conform(value)

    unless S.invalid?(conformed)
      return [@keys[index], conformed]
    end
  end

  :"Speculation/invalid"
end
explain(path, via, inn, value) click to toggle source
# File lib/speculation/spec/or_spec.rb, line 46
def explain(path, via, inn, value)
  return if S.pvalid?(self, value)

  @named_specs.flat_map do |(key, pred)|
    next if S.pvalid?(pred, value)
    S.explain1(pred, Utils.conj(path, key), via, inn, value)
  end
end
gen(overrides, path, rmap) click to toggle source
# File lib/speculation/spec/or_spec.rb, line 59
def gen(overrides, path, rmap)
  return @gen.call if @gen

  gs = @keys.zip(@preds).
    map { |(k, p)|
      rmap = S.inck(rmap, @id)

      unless S.recur_limit?(rmap, @id, path, k)
        Gen.delay { S.gensub(p, overrides, Utils.conj(path, k), rmap) }
      end
    }.
    compact

  unless gs.empty?
    ->(rantly) { rantly.branch(*gs) }
  end
end
unform(value) click to toggle source
# File lib/speculation/spec/or_spec.rb, line 39
def unform(value)
  spec_name, conformed_val = value
  spec = @named_specs.fetch(spec_name)

  S.unform(spec, conformed_val)
end
with_gen(gen) click to toggle source
# File lib/speculation/spec/or_spec.rb, line 55
def with_gen(gen)
  self.class.new(@named_specs, gen)
end