Class: LIVR::Rules::Meta::Or

Inherits:
LIVR::Rule show all
Defined in:
lib/livr/rules/meta.rb

Instance Method Summary collapse

Constructor Details

#initialize(*rule_sets) ⇒ Or

Returns a new instance of Or.


171
172
173
174
175
176
177
# File 'lib/livr/rules/meta.rb', line 171

def initialize(*rule_sets)
  @rule_sets = rule_sets
  @validators = @rule_sets.map do |rules|
    livr = { field: rules }
    Validator.new(livr).prepare
  end
end

Instance Method Details

#call(value, user_data, field_results) ⇒ Object


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/livr/rules/meta.rb', line 179

def call(value, user_data, field_results)
  return if is_no_value(value)

  last_error = nil
  @validators.each do |validator|
    result = validator.validate(field: value)
    if result
      field_results << result[:field]
      return nil
    else
      last_error = validator.get_errors[:field]
    end
  end

  last_error ? last_error : nil
end