Sha256: 3da3505bc1a24c1ac33f1536d8590bc182f60539590b71721862e30c651ddcd4

Contents?: true

Size: 728 Bytes

Versions: 1

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true
module Speculation
  # @private
  class RegexSpec < SpecImpl
    include NamespacedSymbols
    S = Speculation

    def initialize(regex)
      @regex = regex
    end

    def conform(value)
      if value.nil? || Utils.collection?(value)
        S.re_conform(@regex, value)
      else
        ns(S, :invalid)
      end
    end

    def explain(path, via, inn, value)
      if value.nil? || Utils.collection?(value)
        S.re_explain(path, via, inn, @regex, value || [])
      else
        [{ :path => path, :val => value, :via => via, :in => inn }]
      end
    end

    def gen(overrides, path, rmap)
      return @gen if @gen

      S.re_gen(@regex, overrides, path, rmap)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
speculation-0.2.0 lib/speculation/spec_impl/regex_spec.rb