Class: Shamu::Auditing::Transaction
- Inherits:
-
Services::Request
- Object
- Services::Request
- Shamu::Auditing::Transaction
- Includes:
- Shamu::Attributes, 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
-
#action ⇒ String
The primitive action that was requested, such as
add,remove, orchange. -
#changes ⇒ Hash
The changes by attribute requested in the transaction.
-
#user_id_chain ⇒ Array<Object>
The chain of user ids making the request.
Instance Method Summary collapse
-
#append_entity(entity) ⇒ Object
Appends a child node to the #entity_path.
-
#apply_to(model) ⇒ model
Applies the attributes of the request to the given model.
Methods included from Entities::EntityPath
compose_entity_path, decompose_entity_path
Methods included from Shamu::Attributes
#[], #assign_attributes, association, associations, attribute, #attribute?, attributes, #initialize, #set?, #to_attributes
Methods inherited from Services::Request
coerce, coerce!, model_name, #persisted?
Methods included from Shamu::Attributes::Validation
attribute, #valid?, #validated?
Methods included from Shamu::Attributes::Assignment
Instance Attribute Details
#action ⇒ String
Returns 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 |
#changes ⇒ Hash
Returns the changes by attribute requested in the transaction.
24 |
# File 'lib/shamu/auditing/transaction.rb', line 24 attribute :changes |
#user_id_chain ⇒ Array<Object>
Returns the chain of user ids making the request.
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.
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.
46 47 48 49 50 |
# File 'lib/shamu/auditing/transaction.rb', line 46 def apply_to( model ) super.tap do model.changes_json = changes.to_json if changes.present? end end |