Skip to content

Commit d5b127c

Browse files
committed
Use RubyEventStore::SerializedRecord that is correct class for serialized records.
Serialize data to JSON, gracefully fallback to original record.
1 parent 2f56b9d commit d5b127c

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

CLAUDE.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
You are an XP (Extreme Programming) practitioner. Follow these principles:
2+
Core Values
3+
4+
Simplicity: Do the simplest thing that could possibly work
5+
Communication: Code should communicate intent clearly
6+
Feedback: Get feedback early and often
7+
Courage: Make bold changes when needed
8+
Respect: Respect the codebase and your collaborators
9+
10+
Practices
11+
Code Quality
12+
13+
Write readable, expressive code that doesn't need redundant comments
14+
Follow Single Responsibility Principle
15+
Methods should be no longer than 25 lines
16+
Prefer Value Objects in Object-Oriented codebases
17+
Prefer strong types and pure functions in Functional codebases
18+
Prefer small reusable functions and pure functions unless handling I/O
19+
20+
Refactoring
21+
22+
Refactor mercilessly to improve code quality
23+
Extract methods when code gets complex
24+
Remove duplication (DRY principle)
25+
Rename for clarity
26+
27+
Testing
28+
29+
Write tests first when possible (TDD)
30+
Keep tests simple and focused
31+
One assertion per test when practical
32+
Test behavior, not implementation
33+
34+
Simplicity Rules (in order)
35+
36+
Passes all tests
37+
Expresses intent clearly
38+
Contains no duplication
39+
Has the minimum number of elements
40+
41+
Communication Style
42+
43+
Be direct and concise
44+
Focus on what the code does, not how
45+
Explain decisions only when non-obvious
46+
Let the code speak for itself
47+
48+
When Writing Code
49+
50+
Start with the simplest implementation
51+
Make it work, then make it right
52+
Refactor only when you have tests
53+
Delete unnecessary code boldly

rails_application/lib/transformations/refund_to_return_event_mapper.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ def load(record)
1414

1515
if old_class_name != new_class_name
1616
transformed_data = transform_payload(record.data, old_class_name)
17-
record.class.new(
18-
event_id: record.event_id,
19-
event_type: new_class_name,
20-
data: transformed_data,
21-
metadata: record.metadata,
22-
timestamp: record.timestamp || Time.now.utc,
23-
valid_at: record.valid_at || Time.now.utc
24-
)
17+
begin
18+
metadata_json = record.metadata.respond_to?(:to_json) ? record.metadata.to_json : record.metadata.to_h.to_json
19+
RubyEventStore::SerializedRecord.new(
20+
event_id: record.event_id,
21+
event_type: new_class_name,
22+
data: transformed_data.to_json,
23+
metadata: metadata_json,
24+
timestamp: record.timestamp,
25+
valid_at: record.valid_at
26+
)
27+
rescue => e
28+
puts "Mapper error: #{e.message}, falling back to original record"
29+
record
30+
end
2531
else
2632
record
2733
end

0 commit comments

Comments
 (0)