Class: Validatable::ValidationBase

Inherits:
Object
  • Object
show all
Defined in:
lib/validatable/validations/validation_base.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, attribute, options = {}) ⇒ ValidationBase

Returns a new instance of ValidationBase.



6
7
8
9
10
# File 'lib/validatable/validations/validation_base.rb', line 6

def initialize(klass, attribute, options={})
  self.klass = klass
  options.each{|k, v| self.send :"#{k}=", v}
  self.attribute = attribute
end

Instance Attribute Details

#after_validateObject

Returns the value of attribute after_validate.



3
4
5
# File 'lib/validatable/validations/validation_base.rb', line 3

def after_validate
  @after_validate
end

#allow_blankObject

Returns the value of attribute allow_blank.



3
4
5
# File 'lib/validatable/validations/validation_base.rb', line 3

def allow_blank
  @allow_blank
end

#allow_nilObject

Returns the value of attribute allow_nil.



3
4
5
# File 'lib/validatable/validations/validation_base.rb', line 3

def allow_nil
  @allow_nil
end

#attributeObject

Returns the value of attribute attribute.



4
5
6
# File 'lib/validatable/validations/validation_base.rb', line 4

def attribute
  @attribute
end

#ifObject

Returns the value of attribute if.



3
4
5
# File 'lib/validatable/validations/validation_base.rb', line 3

def if
  @if
end

#klassObject

Returns the value of attribute klass.



4
5
6
# File 'lib/validatable/validations/validation_base.rb', line 4

def klass
  @klass
end

#message=(value) ⇒ Object

Sets the attribute message

Parameters:

  • value

    the value to set the attribute message to.



3
4
5
# File 'lib/validatable/validations/validation_base.rb', line 3

def message=(value)
  @message = value
end

Instance Method Details

#validate(instance) ⇒ Object



12
13
14
15
16
# File 'lib/validatable/validations/validation_base.rb', line 12

def validate instance
  if should_validate?(instance) and !valid?(instance)
    instance.errors.add attribute, message(self)
  end
end