Module: ValidationHints::ValidationsPatch

Defined in:
lib/validation_hints/validations_patch.rb

Class Method Summary collapse

Class Method Details

.applied?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/validation_hints/validations_patch.rb', line 35

def self.applied?
  @applied
end

.apply!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/validation_hints/validations_patch.rb', line 5

def self.apply!
  return if applied?

  ActiveModel::Validations::ClassMethods.module_eval do
    def has_validations?
      !validators.empty?
    end

    def has_validations_for?(attribute)
      !validators_on(attribute).empty?
    end
  end

  ActiveModel::Validations.module_eval do
    def has_validations?
      self.class.has_validations?
    end

    def has_validations_for?(attribute)
      self.class.has_validations_for?(attribute)
    end

    def hints
      @hints ||= ActiveModel::Hints.new(self)
    end
  end

  @applied = true
end