Class: Goldencobra::AttributeValidator

Inherits:
Object
  • Object
show all
Defined in:
app/services/goldencobra/attribute_validator.rb

Class Method Summary collapse

Class Method Details

.validate_url(model_name, attribute_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/goldencobra/attribute_validator.rb', line 6

def self.validate_url(model_name, attribute_name)
  return "Not a valid model name" unless is_class?(model_name)
  return "Not a valid attribute on #{model_name}" unless is_attribute?(model_name, attribute_name)

  klass = "#{model_name}".constantize
  results = []
  klass.all.each do |k|
    unless single_scheme_occurence(k.send(attribute_name.to_sym))

      old_attr_value = k.send(attribute_name.to_sym)

      new_attr_value = Goldencobra::AttributeRepairService.repaired_url_value(old_attr_value)

      results << {
        class: model_name,
        id: k.id,
        old_attr_value: old_attr_value,
        new_attr_value: new_attr_value
      }
    end
  end

  results
end