Class: DataShift::Populators::InsistentAssignment

Inherits:
Object
  • Object
show all
Extended by:
Logging
Includes:
Logging
Defined in:
lib/datashift/populators/insistent_assignment.rb

Class Method Summary collapse

Methods included from Logging

logdir, logdir=, logger, verbose

Class Method Details

.call(record, value, operator) ⇒ Object

Raises:

  • (DataProcessingError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/datashift/populators/insistent_assignment.rb', line 31

def self.call(record, value, operator)

  logger.debug("Attempting Brute force assignment of value #{value} => [#{operator}]")

  return if(attempt(record, value, operator))

  method_list = [operator]

  unless operator.include?('=')
    op = operator + '='

    return if(attempt(record, value, op))
    return if(attempt(record, value, op.downcase))

    method_list += [op,  op.downcase]
  end

  method_list.each do |method|
    InsistentAssignment.insistent_method_list.each do |f|
      begin
        return if(attempt(record, value.send(f), method))
      rescue StandardError
      end
    end
  end

  raise DataProcessingError, "Failed to assign [#{value}] to #{operator}" unless value.nil?

end

.insistent_find_by_listObject

When looking up an association, when no field provided, try each of these in turn till a match i.e find_by_name, find_by_title, find_by_id



27
28
29
# File 'lib/datashift/populators/insistent_assignment.rb', line 27

def self.insistent_find_by_list
  @insistent_find_by_list ||= %i[name title id]
end

.insistent_method_listObject



21
22
23
# File 'lib/datashift/populators/insistent_assignment.rb', line 21

def self.insistent_method_list
  @insistent_method_list ||= %i[to_s downcase to_i to_f to_b]
end