mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Encapsulate enrichment actions, add tests
This commit is contained in:
@@ -17,15 +17,11 @@ class Rule::ActionExecutor::SetTransactionCategory < Rule::ActionExecutor
|
||||
end
|
||||
|
||||
scope.each do |txn|
|
||||
Rule.transaction do
|
||||
txn.log_enrichment!(
|
||||
attribute_name: "category_id",
|
||||
attribute_value: category.id,
|
||||
source: "rule"
|
||||
)
|
||||
|
||||
txn.update!(category: category)
|
||||
end
|
||||
txn.enrich_attribute(
|
||||
:category_id,
|
||||
category.id,
|
||||
source: "rule"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,14 +17,11 @@ class Rule::ActionExecutor::SetTransactionMerchant < Rule::ActionExecutor
|
||||
end
|
||||
|
||||
scope.each do |txn|
|
||||
Rule.transaction do
|
||||
txn.log_enrichment!(
|
||||
attribute_name: "merchant_id",
|
||||
attribute_value: merchant.id,
|
||||
source: "rule"
|
||||
)
|
||||
txn.update!(merchant: merchant)
|
||||
end
|
||||
txn.enrich_attribute(
|
||||
:merchant_id,
|
||||
merchant.id,
|
||||
source: "rule"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,14 +16,11 @@ class Rule::ActionExecutor::SetTransactionName < Rule::ActionExecutor
|
||||
end
|
||||
|
||||
scope.each do |txn|
|
||||
Rule.transaction do
|
||||
txn.entry.log_enrichment!(
|
||||
attribute_name: "name",
|
||||
attribute_value: value,
|
||||
source: "rule"
|
||||
)
|
||||
txn.entry.update!(name: value)
|
||||
end
|
||||
txn.entry.enrich_attribute(
|
||||
:name,
|
||||
value,
|
||||
source: "rule"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,15 +17,11 @@ class Rule::ActionExecutor::SetTransactionTags < Rule::ActionExecutor
|
||||
end
|
||||
|
||||
rows = scope.each do |txn|
|
||||
Rule.transaction do
|
||||
txn.log_enrichment!(
|
||||
attribute_name: "tag_ids",
|
||||
attribute_value: [ tag.id ],
|
||||
source: "rule"
|
||||
)
|
||||
|
||||
txn.update!(tag_ids: [ tag.id ])
|
||||
end
|
||||
txn.enrich_attribute(
|
||||
:tag_ids,
|
||||
[ tag.id ],
|
||||
source: "rule"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user