Sha256: 820bacc3fbf529a74b94b22ecd62fe143c6644027571cbcdbf07c0ad67906fdb

Contents?: true

Size: 602 Bytes

Versions: 2

Compression:

Stored size: 602 Bytes

Contents

require "membrane/errors"
require "membrane/schema/base"

module Membrane
  module Schema
  end
end

class Membrane::Schema::Regexp < Membrane::Schema::Base
  attr_reader :regexp

  def initialize(regexp)
    @regexp = regexp
  end

  def validate(object)
    if !object.kind_of?(String)
      emsg = "Expected instance of String, given instance of #{object.class}"
      raise Membrane::SchemaValidationError.new(emsg)
    end

    if !regexp.match(object)
      emsg = "Value #{object} doesn't match regexp #{@regexp}"
      raise Membrane::SchemaValidationError.new(emsg)
    end

    nil
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
membrane-0.0.2 lib/membrane/schema/regexp.rb
membrane-0.0.1 lib/membrane/schema/regexp.rb