Class: Ea::Validation::GridReferenceValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/ea/validation/grid_reference_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ GridReferenceValidator

Returns a new instance of GridReferenceValidator.



8
9
10
11
12
# File 'lib/ea/validation/grid_reference_validator.rb', line 8

def initialize(options)
  @message = options[:message]
  @allow_blank = options[:allow_blank]
  super options
end

Instance Attribute Details

#allow_blankObject (readonly)

Returns the value of attribute allow_blank.



7
8
9
# File 'lib/ea/validation/grid_reference_validator.rb', line 7

def allow_blank
  @allow_blank
end

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/ea/validation/grid_reference_validator.rb', line 7

def message
  @message
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/ea/validation/grid_reference_validator.rb', line 7

def value
  @value
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



14
15
16
17
18
19
# File 'lib/ea/validation/grid_reference_validator.rb', line 14

def validate_each(record, attribute, value)
  @value = value
  return true if allow_blank && value.blank?
  return true unless os_map_ref_detects_error? || invalid_pattern?
  record.errors.add attribute, message
end