Sha256: 326eb88aa893e8b1d54b46d05cbd3add2196d9b3b5fe8bdede83a75090296463

Contents?: true

Size: 723 Bytes

Versions: 2

Compression:

Stored size: 723 Bytes

Contents

# frozen_string_literal: true

require "key_vortex/constraint"
require "key_vortex/limitation"

class KeyVortex
  class Field
    attr_reader :name, :limitation

    def initialize(name, type, *constraints_array, **constraints_hash)
      @name = name
      @limitation = KeyVortex::Limitation.new(type)

      @limitation.add_constraint(*constraints_array)
      @limitation.add_constraint(*constraints_hash.map do |attribute, value|
        KeyVortex::Constraint.build(attribute, value)
      end)
    end

    def within?(adapter)
      limitation = adapter.limitation_for(self)
      !limitation || self.limitation.within?(limitation)
    end

    def accepts?(value)
      limitation.accepts?(value)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
key-vortex-0.2.1 lib/key_vortex/field.rb
key-vortex-0.2.0 lib/key_vortex/field.rb