class Mv::Core::Services::SayConstraintsDiff

Attributes

new_constraint[R]
old_constraint[R]

Public Class Methods

new(old_constraint, new_constraint) click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 11
def initialize(old_constraint, new_constraint)
  @old_constraint = old_constraint   
  @new_constraint = new_constraint
end

Public Instance Methods

execute() { || ... } click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 16
def execute
  ::ActiveRecord::Migration.say_with_time("#{constraint_operation} #{constraint_presenter} on table \"#{table_name}\"") do
    comparison[:deleted].each do |validation|
      say("delete #{validation_presenter(validation)}")
    end if comparison[:deleted]

    comparison[:added].each do |validation|
      say("create #{validation_presenter(validation)}")
    end if comparison[:added]

    yield
  end unless comparison.blank?
end

Private Instance Methods

comparison() click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 51
def comparison
  @comparison ||= Mv::Core::Services::CompareConstraints.new(old_constraint, new_constraint)
                                                        .execute
end
constraint_operation() click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 32
def constraint_operation
  return 'create' unless old_constraint
  return 'delete' unless new_constraint
  'update'
end
constraint_presenter() click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 43
def constraint_presenter
  Mv::Core::Presenter::Constraint::Description.new((old_constraint || new_constraint).description)
end
say(msg) click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 60
def say msg
  ::ActiveRecord::Migration.say(msg, true)
end
say_with_time(msg, &block) click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 56
def say_with_time msg, &block
  ::ActiveRecord::Migration.say_with_time(msg, &block)
end
table_name() click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 38
def table_name
  old_constraint.try(:validations).try(:first).try(:table_name) ||
  new_constraint.try(:validations).try(:first).try(:table_name)
end
validation_presenter(validation) click to toggle source
# File lib/mv/core/services/say_constraints_diff.rb, line 47
def validation_presenter validation
  Mv::Core::Presenter::Validation::Base.new(validation)
end