Sha256: 17d790aad36a3ec2b3f7073c304fab4e6db094a793571ba46a66d82c5a3efef3

Contents?: true

Size: 921 Bytes

Versions: 7

Compression:

Stored size: 921 Bytes

Contents

# frozen_string_literal: true

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

      V32 = '3.2'

      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 >= V32
            base.class_eval(<<-RUBY)
              def initialize(arg)
                self.attributes=arg
                run_validations!
              end
            RUBY
          end
        end
      end

      private_constant :V32
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
u-attributes-1.2.0 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-1.1.1 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-1.1.0 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-1.0.1 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-1.0.0 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-0.14.0 lib/micro/attributes/features/activemodel_validations.rb
u-attributes-0.13.0 lib/micro/attributes/features/activemodel_validations.rb