Method: Validatable::Macros#include_validations_from

Defined in:
lib/macros.rb

#include_validations_from(attribute_to_validate, options = {}) ⇒ Object

call-seq: include_validations_from(attribute)

Includes all the validations that are defined on the attribute.

class Person
  include Validatable
  validates_presence_of :name
end

class PersonPresenter
  include Validatable
  include_validataions_from :person
  attr_accessor :person
  def name
    person.name
  end

  def initialize(person)
    @person = person
  end
end

presenter = PersonPresenter.new(Person.new)
presenter.valid? #=> false
presenter.errors.on(:name) #=> "can't be blank"

The name attribute whose validations should be added.



300
301
302
# File 'lib/macros.rb', line 300

def include_validations_from(attribute_to_validate, options = {})
  validations_to_include << IncludedValidation.new(attribute_to_validate)
end