class Mv::Core::Services::CompareConstraintArrays

Attributes

new_constraints[R]
old_constraints[R]

Public Class Methods

new(old_constraints, new_constraints) click to toggle source
# File lib/mv/core/services/compare_constraint_arrays.rb, line 7
def initialize(old_constraints, new_constraints)
  @old_constraints = old_constraints
  @new_constraints = new_constraints
end

Public Instance Methods

execute() click to toggle source
# File lib/mv/core/services/compare_constraint_arrays.rb, line 12
def execute
  {
    deleted: deleted_constraints, 
    updated: updated_constraints, 
    added: added_constraints
  }.delete_if{ |key, value| value.blank? }
end

Private Instance Methods

added_constraints() click to toggle source
# File lib/mv/core/services/compare_constraint_arrays.rb, line 40
def added_constraints
  new_constraints.select do |new_constraint| 
    old_constraints.none? do |old_constraint| 
      old_constraint.description == new_constraint.description
    end
  end
end
deleted_constraints() click to toggle source
# File lib/mv/core/services/compare_constraint_arrays.rb, line 22
def deleted_constraints
  old_constraints.select do |old_constraint| 
    new_constraints.none? do |new_constraint| 
      old_constraint.description == new_constraint.description
    end
  end
end
updated_constraints() click to toggle source
# File lib/mv/core/services/compare_constraint_arrays.rb, line 30
def updated_constraints
  old_constraints.inject([]) do |res, old_constraint| 
    new_constraints.select do |new_constraint| 
      old_constraint.description == new_constraint.description &&
      old_constraint.validations.sort != new_constraint.validations.sort
    end.each{|new_constraint| res << [old_constraint, new_constraint]}
    res
  end
end