Sha256: 127350f7f5c351e6007cbce66793f98ddc586b0ee9b898d57670a4e48a0fa4c9

Contents?: true

Size: 802 Bytes

Versions: 4

Compression:

Stored size: 802 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

    def enable_json_additions
      @limitation.enable_json_additions
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
key-vortex-0.2.5 lib/key_vortex/field.rb
key-vortex-0.2.4 lib/key_vortex/field.rb
key-vortex-0.2.3 lib/key_vortex/field.rb
key-vortex-0.2.2 lib/key_vortex/field.rb