Class: Shamu::Auditing::Transaction

Inherits:
Services::Request show all
Includes:
Entities::EntityPath
Defined in:
lib/shamu/auditing/transaction.rb

Overview

An audit record of a discrete change transaction.

Constant Summary

Constants inherited from Services::Request

Services::Request::REQUEST_ACTION_PATTERN

Attributes collapse

Instance Method Summary collapse

Methods included from Entities::EntityPath

#compose_entity_path, #decompose_entity_path

Methods inherited from Services::Request

coerce, coerce!, #complete, model_name, #on_complete, #on_fail, #on_success, #persisted?

Methods included from Shamu::Attributes::Validation

attribute, #valid?, #validated?

Methods included from Shamu::Attributes::Assignment

#[]=, #assigned?, #assigned_attributes, attribute, #unassigned_attributes

Methods included from Shamu::Attributes

#[], #assign_attributes, association, associations, attribute, #attribute?, attributes, #initialize, #set?, #slice, #to_attributes

Instance Attribute Details

#actionString

Returns the primitive action that was requested, such as add, remove, or change.

Returns:

  • (String)

    the primitive action that was requested, such as add, remove, or change.



20
# File 'lib/shamu/auditing/transaction.rb', line 20

attribute :action, presence: true

#changesHash

Returns the changes by attribute requested in the transaction.

Returns:

  • (Hash)

    the changes by attribute requested in the transaction.



24
# File 'lib/shamu/auditing/transaction.rb', line 24

attribute :changes

#user_id_chainArray<Object>

Security::Principal in place at the time of the request.

Returns:

  • (Array<Object>)

    the chain of user ids from the



15
# File 'lib/shamu/auditing/transaction.rb', line 15

attribute :user_id_chain, presence: true

Instance Method Details

#append_entity(entity) ⇒ Object #append_entity(pair) ⇒ Object

Appends a child node to the #entity_path.

Overloads:

  • #append_entity(entity) ⇒ Object

    Parameters:

  • #append_entity(pair) ⇒ Object

    Parameters:

    • pair (Array<String,Object>)

      consisting of entity class and id.



40
41
42
43
# File 'lib/shamu/auditing/transaction.rb', line 40

def append_entity( entity )
  @entities ||= []
  entities << entity
end

#apply_to(model) ⇒ model

Applies the attributes of the request to the given model. Only handles scalar attributes. For more complex associations, override in a custom Request class.

Parameters:

  • model (Object)

    or object to apply the attributes to.

Returns:

  • (model)


46
47
48
49
50
# File 'lib/shamu/auditing/transaction.rb', line 46

def apply_to( model )
  super.tap do
    assign_changes_to_model model
  end
end

#entities?Boolean

Returns true if entities have been added to the transaction.

Returns:

  • (Boolean)

    true if entities have been added to the transaction.



53
54
55
# File 'lib/shamu/auditing/transaction.rb', line 53

def entities?
  entities.present?
end