Sha256: 047c6cac99c064e9252fd974fdde457e00c53d05e517d737a6a64180b911d17a

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true
module Speculation
  using NamespacedSymbols.refine(self)

  # @private
  class RegexSpec < SpecImpl
    S = Speculation

    def initialize(regex)
      @regex = regex
    end

    def conform(value)
      if value.nil? || Utils.collection?(value)
        S.re_conform(@regex, value)
      else
        :invalid.ns
      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.1.0 lib/speculation/spec_impl/regex_spec.rb