Class: Dsu::Validators::ColorThemeValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/dsu/validators/color_theme_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dsu/validators/color_theme_validator.rb', line 9

def validate(record)
  default_theme_colors = record.class::DEFAULT_THEME_COLORS

  # return unless validate_color_theme_keys!(record, default_theme_colors)

  default_theme_colors.each_key do |theme_color_key|
    theme_colors_hash = record.public_send(theme_color_key)

    next unless validate_theme_color_type!(record, theme_color_key, theme_colors_hash)

    if theme_colors_hash.empty?
      record.errors.add(:base, ":#{theme_color_key} colors Hash is empty")
      next
    end

    validate_theme_colors!(record, theme_colors_hash)
  end
end