Class: KDomain::DomainModel::Validates

Inherits:
Object
  • Object
show all
Defined in:
lib/k_domain/schemas/domain/old/validates.rb

Constant Summary collapse

KEYS =
%i[length unless format presence].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formatObject

Returns the value of attribute format.



12
13
14
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 12

def format
  @format
end

#lengthObject

Returns the value of attribute length.



10
11
12
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 10

def length
  @length
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 8

def name
  @name
end

#presenceObject

Returns the value of attribute presence.



13
14
15
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 13

def presence
  @presence
end

#unlessObject

Returns the value of attribute unless.



11
12
13
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 11

def unless
  @unless
end

Instance Method Details

#for_template(value) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 31

def for_template(value)
  return nil if value.nil?
  return value.to_s if value.is_a?(Hash)
  return ":#{value}" if value.is_a?(Symbol)

  value
end

#format_formatObject



23
24
25
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 23

def format_format
  for_template(self.format)
end

#format_lengthObject



15
16
17
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 15

def format_length
  for_template(length)
end

#format_presenceObject



27
28
29
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 27

def format_presence
  for_template(presence)
end

#format_unlessObject



19
20
21
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 19

def format_unless
  for_template(self.unless)
end

#to_hObject



39
40
41
42
43
44
45
46
47
# File 'lib/k_domain/schemas/domain/old/validates.rb', line 39

def to_h
  {
    name: name,
    length: length,
    unless: self.unless,
    format: self.format,
    presence: presence
  }
end