Class: LIVR::Rules::Meta::ListOfObjects

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

Instance Method Summary collapse

Constructor Details

#initialize(livr) ⇒ ListOfObjects

Returns a new instance of ListOfObjects.


89
90
91
# File 'lib/livr/rules/meta.rb', line 89

def initialize(livr)
  @validator = Validator.new(livr).prepare
end

Instance Method Details

#call(objects, user_data, field_results) ⇒ Object


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/livr/rules/meta.rb', line 93

def call(objects, user_data, field_results)
  return if is_no_value(objects)
  return 'FORMAT_ERROR' unless objects.is_a?(Array)

  results = []
  errors = []
  has_errors = false

  objects.each do |object|
    result = @validator.validate(object)

    if result
      results << result
      errors << nil
    else
      has_errors = true
      errors << @validator.get_errors
      results << nil
    end
  end

  if has_errors
    return errors
  else
    field_results << results
    return
  end

end