Class: Journaled::ChangeDefinition

Inherits:
Object
  • Object
show all
Defined in:
app/models/journaled/change_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_names:, logical_operation:) ⇒ ChangeDefinition

Returns a new instance of ChangeDefinition.



6
7
8
9
10
# File 'app/models/journaled/change_definition.rb', line 6

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

Instance Attribute Details

#attribute_namesObject (readonly)

Returns the value of attribute attribute_names.



4
5
6
# File 'app/models/journaled/change_definition.rb', line 4

def attribute_names
  @attribute_names
end

#logical_operationObject (readonly)

Returns the value of attribute logical_operation.



4
5
6
# File 'app/models/journaled/change_definition.rb', line 4

def logical_operation
  @logical_operation
end

Instance Method Details

#validate!(model) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/journaled/change_definition.rb', line 16

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

#validated?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/models/journaled/change_definition.rb', line 12

def validated?
  @validated
end