Class: GLiveValidator::ValidationDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/g_live_validator/validation_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(validation) ⇒ ValidationDefinition

Returns a new instance of ValidationDefinition.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/g_live_validator/validation_definition.rb', line 6

def initialize( validation )
  if validation.is_a?(ActiveRecord::Reflection::MacroReflection )
    self.active_record = validation.active_record
    self.macro = validation.macro
    self.name = validation.name
    self.options = validation.options
  elsif validation.is_a?( ValidationRule )
    self.active_record = validation.entity_type.constantize
    self.macro = "validates_#{validation.validation}_of"
    self.name = validation.attribute
    self.options = YAML.load( validation.description ) unless validation.description.nil?
  end
end

Instance Attribute Details

#active_recordObject

Returns the value of attribute active_record.



4
5
6
# File 'lib/g_live_validator/validation_definition.rb', line 4

def active_record
  @active_record
end

#macroObject

Returns the value of attribute macro.



4
5
6
# File 'lib/g_live_validator/validation_definition.rb', line 4

def macro
  @macro
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/g_live_validator/validation_definition.rb', line 4

def name
  @name
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/g_live_validator/validation_definition.rb', line 4

def options
  @options
end