Sha256: 3e02cddba95af091a6332380fde2c691bd855def93931f5623736a0f24383011

Contents?: true

Size: 885 Bytes

Versions: 2

Compression:

Stored size: 885 Bytes

Contents

# frozen_string_literal: true

module Micro::Attributes
  module Features
    module ActiveModelValidations
      @@__active_model_load_error = false
      @@__active_model_required = false

      def self.included(base)
        if !@@__active_model_load_error && !@@__active_model_required
          begin
            require 'active_model'
          rescue LoadError => e
            @@__active_model_load_error = true
          end
          @@__active_model_required = true
        end

        unless @@__active_model_load_error
          base.send(:include, ::ActiveModel::Validations)

          if ::ActiveModel::VERSION::STRING >= '3.2'
            base.class_eval(<<-RUBY)
              def initialize(options)
                self.attributes=(options)
                run_validations!
              end
            RUBY
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
u-attributes-0.12.0 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-0.11.0 lib/micro/attributes/features/activemodel_validations.rb