RobertDober/lab42_data_class

View on GitHub
lib/lab42/data_class/constraints/attribute_setters/list_of_attribute_setter.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

require_relative "attribute_setter"
module Lab42
  module DataClass
    module Constraints
      module AttributeSetters
        class ListOfAttributeSetter
          include AttributeSetter

          def cons(value)
            constraint.constraint.(value) or raise ConstraintError,
                                                   "cannot set value #{value} in set(#{attribute}).cons"

            _set_attr!(_value.cons(value))
          end

          def cdr
            _set_attr!(_value.cdr)
          end

          def set_car(value)
            constraint.constraint.(value) or raise ConstraintError,
                                                   "cannot set value #{value} in set(#{attribute}).cons"
            _set_attr!(_value.cdr.cons(value))
          end
        end
      end
    end
  end
end
# SPDX-License-Identifier: Apache-2.0