Sha256: 96779ef66b95f2041e8b85d490fd9da01ec38bcbdd6f9e17ff72a83e50f84948

Contents?: true

Size: 694 Bytes

Versions: 7

Compression:

Stored size: 694 Bytes

Contents

class Journaled::ChangeDefinition
  attr_reader :attribute_names, :logical_operation

  def initialize(attribute_names:, logical_operation:)
    @attribute_names = attribute_names.map(&:to_s)
    @logical_operation = logical_operation
    @validated = false
  end

  def validated?
    @validated
  end

  def validate!(model)
    nonexistent_attribute_names = attribute_names - model.class.attribute_names
    raise <<~ERROR if nonexistent_attribute_names.present?
      Unable to persist #{model} because `journal_changes_to, as: #{logical_operation.inspect}`
      includes nonexistant attributes:

        #{nonexistent_attribute_names.join(', ')}
    ERROR
    @validated = true
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
journaled-2.1.1 app/models/journaled/change_definition.rb
journaled-2.1.0 app/models/journaled/change_definition.rb
journaled-2.0.3 app/models/journaled/change_definition.rb
journaled-2.0.2 app/models/journaled/change_definition.rb
journaled-2.0.1 app/models/journaled/change_definition.rb
journaled-2.0.0 app/models/journaled/change_definition.rb
journaled-2.0.0.rc1 app/models/journaled/change_definition.rb