Sha256: fb5050dd96ec6e909fe869483d9db5754fe3a139f172e2b39a6676144b7dc215

Contents?: true

Size: 778 Bytes

Versions: 3

Compression:

Stored size: 778 Bytes

Contents

# frozen_string_literal: true

module Micro::Attributes
  module Features
    module ActiveModelValidations
      def self.included(base)
        begin
          require 'active_model'

          base.send(:include, ::ActiveModel::Validations)
          base.extend(ClassMethods)
        rescue LoadError
        end
      end

      module ClassMethods
        def __call_after_attribute_assign__(attr_name, options)
          validate, validates = options.values_at(:validate, :validates)

          self.validate(validate) if validate
          self.validates(attr_name, validates.dup) if validates
        end
      end

      private

        def __call_after_micro_attribute
          run_validations! if respond_to?(:run_validations!, true)
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
u-attributes-2.4.0 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-2.3.0 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-2.2.0 lib/micro/attributes/features/activemodel_validations.rb