Module: Interdependence::ActiveModel::ClassMethods

Included in:
ActiveModel::Model::Interdependence::ClassMethods, ActiveModel::Validator::Interdependence::ClassMethods
Defined in:
lib/interdependence/activemodel/class_methods.rb

Overview

Class methods prepended to ActiveModel’s class methods

Prepends methods on ActiveModel::Model and defines the methods on ActiveModel::Validator

Instance Method Summary collapse

Instance Method Details

#validate(*args, &blk) ⇒ undefined

Monkey patch of ActiveModel::Validations::ClassMethods#validate

Catches ActiveModel #validate calls and then passes the arguments along to super. We track validate calls so that our dependency management doesn’t drop the validate calls when dependencies are changed. Should behave the same as the ActiveModel method

Returns:

  • (undefined)

See Also:



44
45
46
47
# File 'lib/interdependence/activemodel/class_methods.rb', line 44

def validate(*args, &blk)
  validate_calls << [args, blk] if args.first.instance_of?(Symbol)
  super
end

#validates_with(*args) ⇒ undefined

Monkey patch of ‘ActiveModel::Validations::ClassMethods#validates_with`

Catches ActiveModel ‘#validates_with` calls (and #validates) and registers the validator with Interdependence. Interdependence separately registers the validator later on using the original AM validates_with method.

Returns:

  • (undefined)

See Also:



22
23
24
25
26
27
28
29
# File 'lib/interdependence/activemodel/class_methods.rb', line 22

def validates_with(*args)
  with = ValidatesWith.new(*args)
  super unless with.attributes?

  with.each do |(attribute, validator), options|
    add_interdependent_validator(attribute, validator, options)
  end
end