Class: SettingsValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- SettingsValidator
- Defined in:
- lib/settingcrazy/settings_validator.rb
Instance Attribute Summary collapse
-
#record ⇒ Object
Returns the value of attribute record.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record.
2 3 4 |
# File 'lib/settingcrazy/settings_validator.rb', line 2 def record @record end |
#settings ⇒ Object
Returns the value of attribute settings.
2 3 4 |
# File 'lib/settingcrazy/settings_validator.rb', line 2 def settings @settings end |
#template ⇒ Object
Returns the value of attribute template.
2 3 4 |
# File 'lib/settingcrazy/settings_validator.rb', line 2 def template @template end |
Instance Method Details
#validate(record) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/settingcrazy/settings_validator.rb', line 4 def validate(record) self.record = record self.settings = record.settings self.template = settings.template if record.persisted? && template.present? # Not to valid setting_values for unsaved owner & Validate only if the template exists template.enums.symbolize_keys.each do |key, name_value_pairs| = template.(key) current_value = settings.send(key) validate_presence(key, current_value) if [:required] validate_singleness(key, current_value) unless [:multiple] validate_dependent(key, current_value, [:dependent]) if [:dependent] && current_value.present? validate_range(key, current_value, name_value_pairs.values) if [:type] != 'text' && current_value.present? end end end |