Sha256: 2f13dda6c28c837810735c2f822be163df609c78d70e20317bd7a823434aabe3

Contents?: true

Size: 790 Bytes

Versions: 4

Compression:

Stored size: 790 Bytes

Contents

module AttributedObject
  module Strict
    def self.included(descendant)
      super
      descendant.send(:extend, ClassExtension)
      descendant.send(:include, InstanceMethods)
    end

    module ClassExtension
      include AttributedObject::Base::ClassExtension

      def _attributed_object_check_type_supported!(type_info)
        AttributedObjectHelpers::TypeCheck.check_type_supported!(type_info)
      end
    end

    module InstanceMethods
      include AttributedObject::Base::InstanceMethods

      def _attributed_object_on_init_attribute(type_info, value, name:, args:)
        type_matches = AttributedObjectHelpers::TypeCheck.check(type_info, value)
        raise TypeError.new(self.class, name, args) if !type_matches
        return value
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
attributed_object-0.3.1 lib/attributed_object/strict.rb
attributed_object-0.3 lib/attributed_object/strict.rb
attributed_object-0.2.2 lib/attributed_object/strict.rb
attributed_object-0.2.1 lib/attributed_object/strict.rb