Sha256: ed4ca59ad18c99f5f9192c6a4e6e26753835ba1f04875b2a8e110492198d468e

Contents?: true

Size: 695 Bytes

Versions: 17

Compression:

Stored size: 695 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

17 entries across 17 versions & 1 rubygems

Version Path
journaled-5.3.1 app/models/journaled/change_definition.rb
journaled-5.3.0 app/models/journaled/change_definition.rb
journaled-5.2.0 app/models/journaled/change_definition.rb
journaled-5.1.1 app/models/journaled/change_definition.rb
journaled-5.1.0 app/models/journaled/change_definition.rb
journaled-5.0.0 app/models/journaled/change_definition.rb
journaled-4.3.0 app/models/journaled/change_definition.rb
journaled-4.2.0 app/models/journaled/change_definition.rb
journaled-4.1.0 app/models/journaled/change_definition.rb
journaled-4.0.0 app/models/journaled/change_definition.rb
journaled-3.1.0 app/models/journaled/change_definition.rb
journaled-3.0.0 app/models/journaled/change_definition.rb
journaled-2.5.0 app/models/journaled/change_definition.rb
journaled-2.4.0 app/models/journaled/change_definition.rb
journaled-2.3.1 app/models/journaled/change_definition.rb
journaled-2.3.0 app/models/journaled/change_definition.rb
journaled-2.2.0 app/models/journaled/change_definition.rb