Class: ValidatesIdentity::Identity

Inherits:
Object
  • Object
show all
Defined in:
lib/validates_identity/identity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, attribute, value, options) ⇒ Identity

Returns a new instance of Identity.



7
8
9
10
11
12
# File 'lib/validates_identity/identity.rb', line 7

def initialize(record, attribute, value, options)
  @record = record
  @attribute = attribute
  @value = value
  @options = options
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/validates_identity/identity.rb', line 5

def attribute
  @attribute
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/validates_identity/identity.rb', line 5

def options
  @options
end

#recordObject (readonly)

Returns the value of attribute record.



5
6
7
# File 'lib/validates_identity/identity.rb', line 5

def record
  @record
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/validates_identity/identity.rb', line 5

def value
  @value
end

Instance Method Details

#formattedObject



26
27
28
29
30
# File 'lib/validates_identity/identity.rb', line 26

def formatted
  return if @validator.nil?

  @validator.formatted
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/validates_identity/identity.rb', line 14

def valid?
  return true if value.blank?
  return false if options[:identity_type].blank?

  validator_class = ValidatesIdentity.get_validator(identity_type, type: options[:only])

  return false if validator_class.nil?

  @validator = validator_class.new(value)
  @validator.valid?
end