Sha256: 01f1d4aa3fcb2d99e7df97c182411118c099767af3b2c842e111e8a8b51ff816

Contents?: true

Size: 545 Bytes

Versions: 1

Compression:

Stored size: 545 Bytes

Contents

# frozen_string_literal: true

class KeyVortex
  class Record
    def self.constraints
      @constraints ||= {}
    end

    def self.field(type, **constraints)
      self.constraints[type] = constraints
    end

    field :id

    def initialize(fields)
      @fields = fields
    end

    def respond_to_missing?(method, *args)
      args.empty? && self.class.field_constraints(method)
    end

    def method_missing(method, *_args)
      @fields[method]
    end

    def self.field_constraints(field)
      @fields[field]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
key-vortex-0.1.2 lib/key_vortex/record.rb